I'm building a website with MVC 5 and Entity Framework 6, implementing the Unit of Work & Repository patterns, and - for flexibility and performance - would like to utilize Entity Framework's snapshot change tracking rather than proxy change tracking. The drawback of this feature is that navigation property fix-up is not done until DetectChanges is called by DbContext.
Adding an item to a collection...
order.LineItems.Add(orderLineItem);
The inverse association will not be updated until DetectChanges is called...
lineItemOrder = orderLineItem.Order; // lineItemOrder == null
dbcontext.DetectChanges();
lineItemOrder = orderLineItem.Order; // lineItemOrder == order
This navigation property fix-up behavior seems too specific to Entity Framework for the level of abstraction I'd like to see. Does this behavior break principles of Domain Driven Design, or can DetectChanges be considered a business transaction?
Aucun commentaire:
Enregistrer un commentaire