[RESOLVED]I cant understand what is wrong in this query and how it should be written

Hello,

I’m trying to get all item in table parsha that has items in table subjects that has items in table language with language id =1

I wrote this

var ParshasList = db.Parshas.Include(s => s.Subjects.Where(la=>la.languageID.Equals(1)));

navigation property :
//items remove for Cleary  
dbo parsha:  public List<Subject> Subjects { get; set; }

dbo Subject:
  public virtual Parsha Parsha { get; set; }
 public int ParshaId { get; set; }

 public int? languageID { get; set; }
public virtual List<language> languages { get; set; }

the Error i’m getting :

The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties. Parameter name: path             

Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.            

Exception Details: System.ArgumentException: The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties. Parameter
name: path
Source Error:

Line 70:         public PartialViewResult _allparsha()
Line 71:         {
Line 72:             var ParshasList = db.Parshas.Include(s => s.Subjects.Where(la=>la.languageID.Equals(1)));
Line 73:              
Line 74:             return PartialView(ParshasList);

 

thanks

ParshasList = db.Parshas.Include(s => s.Subjects).Where(...)

ignatandrei

ParshasList = db.Parshas.Include(s => s.Subjects).Where(...)

Hello ignatandrei ,

 thanks but like this i’m not getting to language property or subject property

john_mm

i’m not getting to language property or subject property

wher are thos edefined?

ignatandrei

john_mm

i’m not getting to language property or subject property

wher are thos edefined?

I’m sorry I don’t understand the question

Try this query

db.Parshas.Where(s => s.Subjects.Any(la => la.languageID == 1)).ToList()

Leave a Reply