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?