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?
A navigation property is an optional property on an entity type that allows for navigation from one end of an association to the other end. Unlike other properties, navigation properties do not carry data.
Navigation properties allow a user to navigate from one entity to another, or from one entity to related entities through an association set. This topic provides examples in query expression syntax of how to navigate relationships through navigation properties in LINQ to Entities queries.
Reference navigation property: A navigation property that holds a reference to a single related entity. Inverse navigation property: When discussing a particular navigation property, this term refers to the navigation property on the other end of the relationship.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With