我应该从实体框架T4模板中删除协会修正代码吗? [英] Should I rip out the Association Fixup code from my Entity Framework T4 Template?

查看:146
本文介绍了我应该从实体框架T4模板中删除协会修正代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以澄清我对实体框架(T4生成的POCO)中的关联修正代码的想法吗?



最近有关修复的评论表示首先不使用它们,并且所有内容都仍然可以使用。



我对这个修复的东西有些困惑 - 似乎没有人喜欢它 - 我当然不会像污染我的POCO(虽然我的原因是由于性能问题),但是我不清楚我真的需要什么样的场景。



如果我在ASP.NET应用程序中使用短期数据上下文生命周期,即每个页面请求(UoW)的新上下文,那么如果我要从T4模板中删除所有的关联修复代码(最后是干净的POCO)?



编辑



我在MSDNFixup Goes Crazy上发现了这个讨论,它提供了一些澄清: http://social.msdn.microsoft.com/Forums/pl-PL/adodotnetentityframework/thread/a757d1fb-1339-422e-a03a-2b90ce4cd692

解决方案

修复只是T4模板生成的代码。 EF根本不需要,EF不使用它。这是ADO.NET团队所做的一些假设,如果您在一方更改POCO,POCO应该是聪明的并修复其导航属性。如果您手动编写实体,而不是使用T4模板,并且您将省略所有修复逻辑,它仍然可以工作。这也是为什么你不需要首先修复代码的原因。



您可以修改T4模板并删除所有修复逻辑。


Can someone clarify my thinking on association fixup code in Entity Framework (T4 generated POCOs) please?

A recent comment regarding fix-up stated 'For example code-first doesn't use them and everything still works'.

I'm a little confused on this fixup stuff - seems no-one likes it - I certainly don't like it polluting my POCOs (though my reason is because of performance issues) yet it is not clear to me in what scenarios would I really need it.

If I am using short-lived data context lifetimes i.e. new context for each page request (UoW) in an ASP.NET application, then should I worry at all if I were to rip out all the association fix-up code from the T4 template (finally nice clean POCOs)?

EDIT

I found this discussion on MSDN 'Fixup Goes Crazy' which does provide some clarification: http://social.msdn.microsoft.com/Forums/pl-PL/adodotnetentityframework/thread/a757d1fb-1339-422e-a03a-2b90ce4cd692

解决方案

Fix up is just a code generated by T4 template. EF doesn't need it at all and EF doesn't use it. It was some assumption done by ADO.NET team that POCOs should be clever and fix their navigation properties if you change it on one side. If you write your entities manually instead of using T4 template and you will omit all fix up logic it will still work. That is also the reason why you don't need fix ups in the code first.

You can modify your T4 template and remove all fix up logic.

这篇关于我应该从实体框架T4模板中删除协会修正代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆