2

In my EF CodeFirst DB, I have two entities:

public class Prod { public int ProductId {get;set;} ...... ...... public ICollection<ProdLang> ProdLangs {get;set;} } public class ProdLang { public int ProdLangId {get;set;} public int LangId {get;set;} public string Name {get;set;} public string Description {get;set;} ...... ...... public Product Product {get;set;} } 

With Eager Loading, I want to load my collection of Prod ordered by ProdLang.Name or ProdLang.Description for example, by a single Langid

What can I do?

Thanks.

2 Answers 2

1

Do you mean load your collection of ProdLang ordered by ... (as opposed to collection of Prod)? If so, this should work

public class Prod { private ICollection<ProdLang> _prodLangs; public ICollection<ProdLang> ProdLangs { get{ return _prodLangs.OrderBy(p => p.Name).ToList(); } set{ _prodLangs = value; } } } 
Sign up to request clarification or add additional context in comments.

Comments

0

I can't see ProductId property in your ProdLang class to join with Prod class, but I think that it exists.

So, you need to do :

var products = from p in Context.Prod.Set from pl in Context.ProdLang.Set where (p.ProductId == pl.ProductId) orderby (pl.Name) select p; 

If you want to get ProdLang details, you can use a dynamic type:

var products = from p in Context.Prod.Set from pl in Context.ProdLang.Set where (p.ProductId == pl.ProductId) orderby (pl.Name) select new { Prod = p, ProdLang = pl }; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.