Asp.net mvc 子类化模型会导致对数据库的更改
我有一个简单的部门模型:Asp.net mvc 子类化模型会导致对数据库的更改,asp.net-mvc,entity-framework,Asp.net Mvc,Entity Framework,我有一个简单的部门模型: public class Department { [Key] [Required] public int ID { get; set; } [Required] public int LeagueID { get; set; } [Required] public string Name { get; set; } public virtual League League { get; set; }
public class Department
{
[Key]
[Required]
public int ID { get; set; }
[Required]
public int LeagueID { get; set; }
[Required]
public string Name { get; set; }
public virtual League League { get; set; }
}
已添加到我的ApplicationDbContext中:
public DbSet<Department> Departments { get; set; }
尽管我没有对IdentityModels进行任何更改,但在更新数据库时,它已经更改了数据库并添加了MemberCount和Discriminator字段。我理解如果我在IdentityModels中引用DepartmentWithCount,为什么会出现这种情况,但我不理解在这种情况下为什么会出现这种情况
有没有办法在没有这些效果的情况下将Department子类化?在子类之前使用[NotMapped]属性
public class DepartmentWithCount : Department
{
public DepartmentWithCount(Department d)
{
this.ID = d.ID;
this.LeagueID = d.LeagueID;
this.Name = d.Name;
}
public int MemberCount { get; set; }
}