我现在正在学习微风,我在使用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;
}
我的viewModel
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");
};
请帮助我
答案 0 :(得分:0)
你没有发布savaChanges方法的代码,我认为你的问题在于这个方法
如果是这种情况,您可以在此处找到答案 Saving Changes using breeze without Entity Framework