【发布时间】:2021-12-06 07:35:07
【问题描述】:
我做了什么:
public class Responses
{
public int UserId { get; set; }
public virtual AppUser AppUser { get; set; }
public int QuestionId { get; set; }
public virtual Question Question { get; set; }
public string Answer { get; set; }
}
public class Question
{
public int idQuestion { get; set; }
public string TextQuestion { get; set; }
public ICollection<Responses> Responses { get; set; }
}
public class AppUser : IdentityUser<int, AppUserLogin, AppUserRole, IdentityUserClaimBase>, ICRMRepository, IEditableEntity, IEntityBase
{
public int idUser {get;set;}
public ICollection<Responses> Responses { get; set; }
}
接下来我去 DbContext:
modelBuilder.Entity<Responses>()
.HasKey(x => new {x.UserId, x.QuestionId});
modelBuilder.Entity<Responses>()
.HasOne(x=>x.User)
无法解析符号“HasOne”
如果我想得到这样的 db,我该怎么办?
如何配置我与 fluent API 的关联?或者有没有更好的方法来创建关联表?
【问题讨论】:
标签: c# asp.net-mvc entity-framework ef-code-first