【问题标题】:Aspnetboilerplate mvc code first generates same field two timesAspnetboilerplate mvc 代码首先生成相同的字段两次
【发布时间】:2017-11-28 03:30:41
【问题描述】:

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

我有如下的用户和部门实体。用户实体确实带有 abp 默认值。太简单了,我已经指定了导航。但是代码首先为我生成了这个愚蠢的数据库。表中有两个用户 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; }
}

【问题讨论】:

    标签: asp.net-mvc-5 ef-code-first aspnetboilerplate


    【解决方案1】:

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

    只需从通用中删除用户。

    public class Department : FullAuditedEntity<int>
    {
    
    }
    
    public class UserDepartment : FullAuditedEntity<int>
    {
    
    }
    

    就是这样。您可以在this link 中了解更多信息,或在this link 中查看实现。

    我希望这很有用。

    【讨论】:

    • 我只删除了 userdepartment 的 : FullAuditedEntity 部分,它按预期工作,感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    • 2014-05-22
    • 2021-05-09
    • 2014-11-13
    • 1970-01-01
    • 2016-08-06
    相关资源
    最近更新 更多