Reputation: 413
I am querying an Entity(Applicant) which has multiple navigation properties, need to include two navigation properties (Worker and StatusType) in the include part of the query.
Tried including one property Worker as .include("Worker") this works, but when I use .include("Worker, StatusType") to get both the navigation properties the query fails with the message 'invalid include path'.
What is the syntax for including multiple navigation properties in Entity Framework?
Upvotes: 12
Views: 4699
Reputation: 256
for example we have two class :
public class Address
{
[Required]
public int ProvinceId { get; set; }
[ForeignKey(nameof(ProvinceId))]
public Province Province { get; set; }
}
public class Province
{
[StringLength(50)]
[Required]
public string Name { get; set; }
}
//Now if you want to include province use code below :
.Include(x => x.Address).ThenInclude(x => x.Province)
Upvotes: 2
Reputation: 10624
Or if it is a subproperty of the property you are including try
.Include("Worker.StatusType")
Upvotes: 6