Should I rip out the Association Fixup code from my Entity Framework T4 Template?

被刻印的时光 ゝ 提交于 2019-12-24 09:30:00

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/6723784/should-i-rip-out-the-association-fixup-code-from-my-entity-framework-t4-template

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