【发布时间】:2015-08-29 02:17:48
【问题描述】:
我有以下型号:
public class ApplicationUser : IdentityUser
{
public int? StudentId { get; set; }
public virtual Student Student { get; set; }
}
public class Student : BaseEntity
{
public string UserId { get; set; }
public virtual ApplicationUser User { get; set; }
public string CreatedById { get; set; }
public virtual ApplicationUser CreatedBy { get; set; }
}
如您所见,Student 和 ApplicationUser 之间有两个一对一关系,因此在 ModelCreating 中我定义了以下内容:
modelBuilder.Entity<ApplicationUser>()
.HasOptional(u => u.Student)
.WithRequired(s => s.User);
当数据库生成时,除了列名之外一切都很好,我希望在 student 中创建的列是 UserId,但是它将 UserId 列创建为一个简单的列,并为关系创建另一个列 User_Id。
如何定义 Student 中的属性 UserId 是关系的属性?
【问题讨论】:
-
我认为您的实体配置不正确...学生必须退出 ApplicationUser,或者用户必须退出 Student...
标签: c# entity-framework entity-framework-6 ef-fluent-api