entity framework navigation property further filter without loading into memory -


I have two entities, between which 1 to N is the relation. Let's say books and pages as a book The navigation property page is book booked as an identifier and the page has a scanner property called an auto-generated ID and page number. LazyLoading is set to the right.

I call it VS2010 & amp; In the partial class of the .NET 4.0 and created a database from that, I need a GetPage function as below.

  Public Page GetPage (int PageNumber) Etc. etc.) are not included for the simplicity returns page. = & Gt; P.PageNo == PageNumber) First (); }  

This works, however, when there is an entity collection in the book property in the book, it has to load all the pages of a book in memory to get a page (this is a This function slows down the app for the first time when the function is killed). That means the framework does not merge questions and run them at one time. This loads the page into memory and then uses LINQ for objects to do the second part

I have changed the following code to overcome it

  Public Page GetPage (int PageNumber) {MyContainer Container = New MyContainer (); Back container pages. Where (P => P. Page No. == Page Number and P. Book Book ID == BookId). first (); }  

It works very fast but it does not take into account those pages which are not ordered for DB.

Therefore, there are conspiracies in both options. Is there any move in the framework to overcome this situation? It should be a normal scenario where you do not want all objects of the navigation property loaded in memory, when you do not need it.

deceit? Also try "both?"

  Public Page GetPage (int page number) {// Check local values, probably not yet released // anything works fine when loaded Var Results = Page Where (P => P. page nozz == page number). FirstOver Default (); If (result! = Null) {return result; } // Check DB if nothing found MyContainer container = new MyContainer (); Return Container Pages Where (P => P. Page no == Page number and p.Book.BookId == BookId). first (); }  

Except for the specific case loading with PK value, there is nothing to do it automatically, for which you can use ObjectContext. [Try] GetObjectByKey . / P>


Comments