I have an entity called Address. An Address contains a complex type, called House. A House contains a reference to its occupants. An Occupant is an entity.
public class Address {
[key]
public int Id { get; set; }
public House House { get; set; }
}
The House:
[ComplexType]
public class House
{
[Required]
public string HouseType { get; set; }
public IList<Occupant> Occupants { get; set; }
}
The occupant
public class Occupant
{
[key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
public virtual Address Address { get; set; }
}
If I use lazyloading everything works fine and i can access all properties. However I need to use EagerLoading as the entities are needed long after the Context has been disposed.
I have tryed to include the properties using this code:
// DbSet is of type DbSet<Address>
List<Address> eagerLoadedEntity = DbSet.Where(a => a.Address.StartsWith("a"))
.Include(a => a.House.Occupants).ToList();
I get the following error:
A specified Include path is not valid. The EntityType 'Address' does not declare a navigation property with the name 'House'.