c# - Doing Eager Loading and Projection in Linq to Entities -


this spin off question posted few days ago answered didn't underlying issue having wasn't able express in original query.

i have table product. product related productdescription in one-to-many relationship. productdescription can have more 1 row each product. have multiple rows if there multiple translations description of product. product has many-to-one relationship language. language has language code (en, es, etc.) languageid (found in productdescription well).

i want give users ability request product , further tell application return descriptions product in specific language.

the problem i'm having understand need use projection accomplish task in 3rd paragraph of question. this:

    var query = inventoryrepository.products                         .where(wherepredicate)                         .select( a=> new product                         {                             productdescriptions = inventoryrepository.objectcontext.productdescriptions                                .where(a => a.languages.alternatecode.equals("en", stringcomparison.currentcultureignorecase))                         }); 

however have 15 properties in products table 4 other child tables of products need loaded result set in addition languages piece. there way me eager loading , projection don't have go through , map of these properties , children objects manually? here code stands right now:

var query = inventoryrepository.objectset                     .include("productdescriptions")                     .include("productallowedwarehouses")                     .include("producttocategories")                     .include("pricelevels")                     .include("attachmentassociations.attachment").asexpandable()                     .where(wherepredicate); 

no select necessary nice. once change productdescriptions projection add select , don't of other properties / children populated free.

i read blog projections+eager loading. going run issues when comes eager loading. recommendation use .any , perform sub select.

why can't add filter/where on productdescriptions?

 var query = inventoryrepository.objectset                 .include("productdescriptions")                 .include("productallowedwarehouses")                 .include("producttocategories")                 .include("pricelevels")                 .include("attachmentassociations.attachment").asexpandable()                 .where(wherepredicate)                 .where(a=>a.productdescriptions.languages.alternatecode.equals("en", stringcomparison.currentcultureignorecase); 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -