0

我现在正在学习微风,我在使用 OData 时遇到微风问题,当我添加一个新实体时,该实体会很好地添加到本地缓存中,但服务器什么也没收到!注:1-我不使用实体框架 2-我使用 wcf 服务

我的模型:

[Serializable()]
    [DataContract()]
    [DataServiceKey("Id")]
    public class Client : EntityBase
    {
        public Client()
        {

        }

        [DataMember()]
        [XmlAttribute()]
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public new int Id { get; set; }

        [DataMember()]
        [XmlAttribute()]

        public String nom {get;set}

        [DataMember()]
        [XmlAttribute()]
        public Adresse adresse { get; set; }

我的控制器

[BreezeController]
    public class ClientController : EntitySetController<Client, int>
    {
        [Queryable]
        [AcceptVerbs("GET")]

        public override IQueryable<Client> Get()
        {
            return new Clients(MyProxy.GetAllClients()).AsQueryable<Client>();

          }


        [AcceptVerbs("POST")]

      protected override Client CreateEntity( Client client)
        {
           MyProxy.CreateClient(client);
            return client;
        }

我的视图模型

var myDataService = new breeze.DataService({
        serviceName: 'odata',
        hasServerMetadata: false
    });

    var myMetadataStore = new breeze.MetadataStore();
    var entityManager = new breeze.EntityManager({
    dataService: myDataService,
metadataStore: myMetadataStore
       });

   var et = new breeze.EntityType({
        shortName: "Client",
        namespace: "MyNameSpace",
         autoGeneratedKeyType: breeze.AutoGeneratedKeyType.Identity,
        defaultResourceName: "Clients"
    });
    et.addProperty(new breeze.DataProperty({
        name: "Id",
            dataType: breeze.DataType.Int32,
            isNullable: false,
        isPartOfKey: true
    }));
    et.addProperty(new breeze.DataProperty({
        name: "Nom",
        dataType: breeze.DataType.String
    }));
  myMetadataStore.addEntityType(et)
  myMetadataStore.setEntityTypeForResourceName("Client", et);
  myMetadataStore.addDataService(myDataService);
var etType = myMetadataStore.getEntityType('Client');
   var newTag = etType.createEntity();
  newTag.Nom = "James";


   if (entityManager.hasChanges() == true) {
       var option = new breeze.SaveOptions({ resourceName: 'Clients' });
       entityManager.saveChanges(null, option)
                .then(
              alert(“OK”)

                }
     )
                .fail(function (e) {

                    alert(e);
                });
   } else {
       alert("Nothing to save");
   };

请帮帮我

4

1 回答 1

0

您没有发布 savaChanges 方法的代码,我认为您的问题出在此方法上

如果是这种情况,您可以在这里找到答案 使用没有实体框架的微风保存更改

于 2013-07-22T00:13:12.047 回答