我想在以下边缘情况下创建一对多关系: 我有一个可以有很多通知的用户。
public class User : IdentityUser
{
public List<SentNotification> SentNotifications { get; set; }
public User()
{
SentNotifications = new List<SentNotification>();
}
}
每个通知都由用户发送并由用户接收。
public class SentNotification
{
public User Receiver { get; set; }
public User Sender { get; set; }
}
当我生成架构时,我收到以下迁移:
public override void Up()
{
CreateTable(
"dbo.SentNotifications",
c => new
{
Id = c.Int(nullable: false, identity: true),
ReceiverId_Id = c.String(maxLength: 128),
SenderId_Id = c.String(maxLength: 128),
User_Id = c.String(maxLength: 128),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.AspNetUsers", t => t.ReceiverId_Id)
.ForeignKey("dbo.AspNetUsers", t => t.SenderId_Id)
.ForeignKey("dbo.AspNetUsers", t => t.User_Id)
.Index(t => t.ReceiverId_Id)
.Index(t => t.SenderId_Id)
.Index(t => t.User_Id);
}
问题: 有没有办法在声明实体让EF生成一个迁移时知道Sender是一对多关系的外键并且没有调整生成的迁移代码?