开发者

EF CTP5 which code generation item to choose?

开发者 https://www.devze.com 2023-02-15 04:16 出处:网络
With EF 4.1 on the way and CTP5 being available for few months now I\'ve decided to try out the new functionality. As I see, there are multiple generation items available (DbContext and three differen

With EF 4.1 on the way and CTP5 being available for few months now I've decided to try out the new functionality. As I see, there are multiple generation items available (DbContext and three different ObjectContext's). I also noticed they are not interchangable - I was first using the POCO ObjectContext in one of my app and today switched to DbContext and my entire repository broke. It was based on LoadProperty() methods, DeleteObject() and AddObject() methods and those are all missing on DbSet class which is used in DbContext generation.

I know there's a great blog series here http://blogs.msdn.com/b/adonet/archive/2011/01/27/using-dbcontext-in-ef-feature-ctp5-part-1-introduction-and-model.aspx introducing the new functionality but it never really says when to choose what.

My requirements are:

  • ASP.NET MVC application, so lazy loading mostly won't work coz at page render it will say that context has already been disposed (that's why I need easy support for explicit loading - in EF4 I did it via Include(), using POCO context I did it through LoadProperty() and now in DbContext I believe I will use the strongly typed Include()).
  • We probably won't be needing code-first features开发者_如何学运维 (but you never know).


Difference between those two is mostly in API and feature set. DbContext of course have Include for query and Load but you will find it elsewhere. Moreover when using CTP5 assembly you will have strongy typed Include for both ObjectSet and DbSet (available on IQueryable interface as extension method).

Explicit loading (equivalent to LoadProperty) is performed by Load method on DbReferenceEntry<T> or DbCollectionEntry<T> - check Explicit loading related entities. It works even better then LoadProperty because you can define filter for loading.


You are starting with the wrong assumption that you can't use lazy load with MVC.

If you manage the context at a higher level, you'll be able to do that without problems.

0

精彩评论

暂无评论...
验证码 换一张
取 消