问题
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,
- 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)
- Where are you assigning the primary key for the "Foo" instance?
- 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