Breeze - Create Entity on Server side

限于喜欢 提交于 2019-12-11 10:49:38

问题


I would like to create my breeze entity on the server side rather than using breeze entitymanager.createEntity, so that I can set properties of the entity; I don't want to do this on the client side.

SERVER SIDE api controller:

[HttpGet]
public Foo CreateFoo() 
{

    Foo f = new Foo()
    {
       PrimaryKey = Guid.NewGuid(),
       SomeProperty = "XXX";
    };

    return f;
    // return _contextProvider.Context.Users.Add(user); TRIED THIS TOO

}

[HttpGet]
public string Metadata()
{
   return _contextProvider.Metadata();
}

CLIENT SIDE -

var query = breeze.EntityQuery.from("CreateFoo");
manager.executeQuery(query).then(function(data) {

    // returned entity has entityState "Unchanged" here

    // this fixes, but is it correct? - YES per accepted answer's comments 
    data.results[0].entityAspect.entityState = breeze.EntityState.Added; 

    return data;
});

I've tried this a number of ways but always get concurrency exceptions on the server side when I call SaveChanges.

How can I do this?


回答1:


Several questions,

  1. Do you have metadata on the client for the "Foo" type. (either via the Metadata endpoint or created on the client with the MetadataStore api)
  2. Where are you assigning the primary key for the "Foo" instance?
  3. Are you updating or at least setting the concurrency field for the "Foo" instance (assuming that have one)?


来源:https://stackoverflow.com/questions/20338591/breeze-create-entity-on-server-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!