I have the following classes:
public class Box
{
public int Id { get; set; }
public DbSet<Item> Items { get; set; }
}
public abstract class Item
{
public int Id { get; set; }
}
public class Toy : Item
{
public string Name { get; set; }
}
public class ElectricToy
: Toy
{
public int Voltage { get; set; }
}
public class WoodenToy
: Toy
{
public string Color { get; set; }
}
A Box has a collection of items which might be electric toys or wooden toys. Now, I want to load all toys in a box with the following code.
var boxes =
db.Boxes
.Where(o => o.Id = id)
.Include(o => o.Items);
It loads all toy but it doesn't load electric and wooden toy values, that is Voltage is always 0 and Color is always null.
How to force Entity Framework to load values for ElectricToy and WoodenToy?