I am querying an Entity(Applicant) which has mu开发者_运维百科ltiple 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?
Use
Include("Worker").Include("StatusType")
Or if it is a subproperty of the property you are including try
.Include("Worker.StatusType")
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)
精彩评论