Say I have the following model -
public class Folder
{
public int Id {get; set;}
public virtual List<Letter> Letters {get; set;
}
public class Letter
{
public int Id {get; set;}
public virtual list<Folder> Folders;
// ...
}
What query should I use to get all letters from a specific folder?
For instance if I want all the letters in folder with Id 1:
If I simply use context.Folders.Find(1).Letters
, it gets me a List instead of an IQueryable<Letter>
, and it gets me some data that is not useful for this specific case.
However if I use context.Letters.Where(x => x.Folders.Any(f => f.Id == 1)
I'm inefficiently iterating through all the Letters which seems bad.