使用MergeOption将存储过程映射到实体框架 [英] Map a Stored Procedure to Entity Framework with MergeOption
问题描述
您可以更新T4模板文件,将MergeOption.NoTracking添加为第二个参数。然后只需R点击.edmx并选择运行自定义工具。
这是一个快速的解决方法,但我也想知道一个更长期的解决方案。如果这是唯一的解决方案,则可以更新默认的T4模板,以便这将自动添加新的EntityModel,并保存它们。
{EnitityModel} .Context.tt
第290行:
return((IObjectContextAdapter)this).ObjectContext.ExecuteFunction {0}(\ {1} \,MergeOption.NoTracking {2});,
在我的Repository构造函数中,但是MergeOption看起来更清洁。
context = new Entities();
context.Configuration.AutoDetectChangesEnabled = false;
context.Configuration.ValidateOnSaveEnabled = false;
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?
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;
这篇关于使用MergeOption将存储过程映射到实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!