If you have an interface for a repository that includes
T Add( T entity);
The Repository wouldn't include a Save() or SaveChanges(). If you were to return "entity" with:
return _dc.Entities.Where( n => n.ID == entity.ID).Singl开发者_开发问答e();
I wouldn't expect this to hit the database and auto-generate identity values (auto-incrementing). Two questions:
- What values would be in the fields for ID assuming it is an identity (auto-incrementing) field?
- When this actually does save, can we expect the identity fields to automatically update in the returned object?
- Is there a command that will update object references from the database outside a repository?
This is using ASP.NET POCO Generator for Entity Framework 4 with virtual properties.
_dc.Entities.Anything
will always hit the DB. LINQ to Entities always hits the db. Even if the object is already in the context.
To avoid a DB query if the object is already in the context, use ObjectContext.GetObjectByKey()
.
An auto-incremented int
or long
will be 0
before you save. Yes, this gets updated when you save. As long as the objects are attached to the context, they'll all see this.
精彩评论