klevendoglu
klevendoglu

Reputation: 622

Aspnetboilerplate mvc code first generates same field two times

I do not know if it's related to abp but, it's possible so I believe someone from community may help me.

I have User and Department entities as below. User entity does come with abp default. It's so simple that I have specified navigation. But code first generates this silly database for me. There are two user ids in the table which makes it hard to track it in the project. why this happens and how to avoid? enter image description here

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; }
}

Upvotes: 0

Views: 126

Answers (1)

gezanoletti
gezanoletti

Reputation: 147

You are inheriting from the FullAuditedEntity generic version that include a navigation property to the User.

Just remove the User from generic.

public class Department : FullAuditedEntity<int>
{

}

public class UserDepartment : FullAuditedEntity<int>
{

}

That's all. You can read more about in this link or check the implementation at this link.

I hope this be useful.

Upvotes: 1

Related Questions