Entity Framework 5 : Using Lazy Loading or Eager Loading

前端 未结 1 1718
孤独总比滥情好
孤独总比滥情好 2021-01-15 23:31

I\'m sorry if my question is normal. But I meet this problem when I design my ASP.NET MVC 4.0 Application using Entity Framework 5.

If I choose Eager Loading, I just

相关标签:
1条回答
  • 2021-01-16 00:00

    Don't use a static DBContext object. See c# working with Entity Framework in a multi threaded server

    A simple rule for ASP.Net MVC: use a DBContext instance per user request.

    As for using lazy loading or not, I would say it depends, but personally I would deactivate lazy-loading. IMO it's a broken feature because there are fundamental issues with it:

    • just too hard to handle exceptions, because a SQL request can fail at any place in your code (not just in the DAL because one developer can access to a navigation property in any piece of code)
    • poor performances if not well used
    • too easy to write broken code that produces thousands of SQL requests
    0 讨论(0)
提交回复
热议问题