Should I rip out the Association Fixup code from m

2019-08-03 09:31发布

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条回答
戒情不戒烟
2楼-- · 2019-08-03 10:08

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.

查看更多
登录 后发表回答