I have 3 entities
public class A
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<AB> ABs { get; set; }
}
public class AB
{
public int AId { get; set; }
public virtual A A { get; set; }
public int BId { get; set; }
public virtual B B { get; set; }
}
public class B
{
public int Id { get; set; }
public virtual ICollection<AB> ABs { get; set; }
}
I need to write the following SQL in Linq :
SELECT * FROM A, AB
WHERE
A.Name = 'name'
AND AB.BId = 1
I've tried:
DbContext.Set<A>().Include(a => a.ABs.Select(ab => ab.B).Where(b => b.Id == 1)).Single(a => a.Name == "name");
DbContext.Set<A>().Include(a => a.ABs.Where(ab => ab.BId == 1)).Single(a => a.Name == "name");
DbContext.Set<A>().Include(a => a.ABs.Select(ab => ab.BId == 1).Single(a => a.Name == "name");
DbContext.Set<A>().Include(a => a.ABs.Any(ab => ab.BId == 1)).Single(a => a.Name == "name");
I always get the same message :
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.
I'd like to understand the error message.
My questions :
- Is "public virtual ICollection ABs" a navigation property ?
- What are dotted paths ?
- What's the difference between "reference navigation properties" and "collection navigation properties" ?
- What should I change to get my request to work ?