请假设这个架构:
public class Mammal
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Dog : Mammal
{
public int TailId { get; set; }
public Tail Tail { get; set; }
}
public class Bat : Mammal
{
public int WingId { get; set; }
public Wing Wing { get; set; }
}
public class Buffalo : Mammal
{
public virtual ICollection<Horn> Horns { get; set; }
}
public class Tail …Run Code Online (Sandbox Code Playgroud) 有没有办法从DbSet继承?我想添加一些新属性,如下所示:
public class PersonSet : DbSet<Person>
{
public int MyProperty { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在我的DbContext中实例化它
public partial MyContext : DbContext
{
private PersonSet _personSet;
public PersonSet PersonSet
{
get
{
_personSet = Set<Person>(); // Cast Error here
_personSet.MyProperty = 10;
return _personSet;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?