Map a Stored Procedure to Entity Framework with MergeOption

妖精的绣舞 提交于 2019-12-13 03:19:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!