Is there a way to set a filter on a navigation property using EF6/code first?
I want to achieve something similar to the below, where Farm.Pigs returns a collection of animals whose type is equal to pig (but without loading the whole collection from the database first - and not storing them in a separate table). Is this possible?
public class Farm {
public int Id { get; set; }
public virtual ICollection<Animal> Pigs { get; set; }
public virtual ICollection<Animal> Cows { get; set; }
}
public class Animal {
public int Id { get; set; }
public int FarmId? { get; set; }
public virtual Farm Farm { get; set; }
public string Name { get; set; }
}
public enum AnimalType {
Pig, Cow
}
Update
Moved the update to a new question: Entity Framework One-Many TPH Mapping