问题
Is there a way to map a stored procedure to Entity Framework in such a way that the ExecuteFunction uses the MergeOption parameter with the NoTracking option?
回答1:
You could update the T4 template file to add "MergeOption.NoTracking" as the 2nd parameters. Then just R-Click on the .edmx and select "Run Custom Tool".
This is a quick workaround but I would also like to know a more long term solution. If this is the only solution, can the default T4 templates be updated so that this is automatic with new EntityModels and were are they stored.
{EnitityModel}.Context.tt Line 290:
"return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction{0}(\"{1}\", MergeOption.NoTracking{2});",
I was setting the following in my Repository constructor, but the MergeOption appears to be cleaner
context = new Entities();
context.Configuration.AutoDetectChangesEnabled = false;
context.Configuration.ValidateOnSaveEnabled = false;
来源:https://stackoverflow.com/questions/13868311/map-a-stored-procedure-to-entity-framework-with-mergeoption