【发布时间】:2016-08-11 08:40:39
【问题描述】:
我有一个模型叫 Sammanhang
[Key]
public int SammanhangsID { get; set; }
public string Namn { get; set; }
我想将用户的 id 作为外键包含在内,这样我就可以获得数据库中所有用户的下拉列表。
我尝试做这样的事情
public class Sammanhang
{
[Key]
public int SammanhangsID { get; set; }
public string Namn { get; set; }
public string UserId { get; set; }
[ForeignKey("UserId")]
public virtual ApplicationUser ApplicationUser { get; set; }
}
在 IdentityModels 内部
public class ApplicationUser : IdentityUser
{
public virtual Sammanhang Sammanhang { get; set; }
}
但是没有成功,请问有没有办法实现用户下拉列表?
【问题讨论】:
-
But without no success- 请详细说明并具体说明。 -
当我尝试在包管理器中“添加迁移”和“更新数据库”时,我得到:“无法确定类型‘IdentitySample.Models.ApplicationUser’之间关联的主体端”和“Checkin.Models.Sammanhang”。必须使用关系流式 API 或数据注释显式配置此关联的主体端。”
-
你的外键注释 UserId 应该在你的 UserId 属性之上。
标签: c# asp.net-mvc asp.net-identity dropdown