我有3个实体:
public class AspNetUser
{
public string Id {get; set;}
}
public class Event
{
public int Id {get; set;}
}
public class UserEvent
{
[Column(Order=0), Key, ForeignKey("AspNetUsers")]
public string UserId { get; set; }
[Column(Order=1), Key, ForeignKey("Events")]
public int EventId { get; set; }
public DateTime EnrolTime { get; set; }
public virtual AspNetUser User { get; set; }
public virtual Event Event { get; set; }
}
正如您所看到的,UserEvent只是一个关系表,它包含来自2个表的UserId和EventId。
我的问题是:
Entity Framework Multiple Column as Primary Key by Fluent Api
谢谢。
答案 0 :(得分:2)
是的,使用数据注释已经足够了,但问题是你需要在ForeignKey
属性中指定导航属性的名称`,它代表了它作为外键的关系:
public class UserEvent
{
[ Key,Column(Order=0), ForeignKey("User")]
public string UserId { get; set; }
[ Key,Column(Order=1), ForeignKey("Event")]
public int EventId { get; set; }
public DateTime EnrolTime { get; set; }
public virtual AspNetUser User { get; set; }
public virtual Event Event { get; set; }
}
或者,您可以将ForeignKey
注释应用于导航属性,并告诉它哪个属性是该关系的外键:
public class UserEvent
{
[Key,Column(Order=0)]
public string UserId { get; set; }
[Key,Column(Order=1)]
public int EventId { get; set; }
public DateTime EnrolTime { get; set; }
[ForeignKey("UserId")]
public virtual AspNetUser User { get; set; }
[ForeignKey("EventId")]
public virtual Event Event { get; set; }
}
答案 1 :(得分:0)
.video-container {
position: relative;
padding-bottom: 37.25%;
padding-top: 25px;
height: 0;
margin-bottom: 30px;
}
.video-container iframe,
.video-container object,
.video-container embed {
position: absolute;
top: 0;
left: 12.5%;
width: 75%!important;
height: 100%!important;
}