Aspnetboilerplate mvc 代码首先生成相同的字段两次

Aspnetboilerplate mvc code first generates same field two times

我不知道它是否与 abp 有关,但是,这是可能的,所以我相信来自社区的人可能会帮助我。

我有如下用户和部门实体。用户实体确实带有 abp 默认值。很简单,我指定了导航。但是代码首先为我生成这个愚蠢的数据库。 table 中有两个用户 ID,因此很难在项目中对其进行跟踪。为什么会发生这种情况以及如何避免?

public class User : AbpUser<User>
{             
    public virtual ICollection<UserDepartment> UserDepartments { get; set; }

}

public class Department : FullAuditedEntity<int, User>
{
    public virtual ICollection<UserDepartment> UserDepartments { get; set; }
}

public class UserDepartment : FullAuditedEntity<int, User>
{
    public virtual long UserId { get; set; }

    [ForeignKey("DepartmentId")]
    public virtual Department Department { get; set; }

    public virtual int DepartmentId { get; set; }

    [ForeignKey("UserId")]
    public virtual User User { get; set; }
}

您正在继承 FullAuditedEntity 通用版本,其中包含 属性 用户导航。

只需从通用中删除用户。

public class Department : FullAuditedEntity<int>
{

}

public class UserDepartment : FullAuditedEntity<int>
{

}

就是这样。您可以在 this link or check the implementation at this link.

中阅读更多相关信息

希望有用。