我正在使用VS 2013,SQL Server 2008 R2。我刚开始学习ASP.NET MVC& EF
我创建了两个类:
public class Album
{
public int Id { get; set; }
//ApplicationUser from Asp.net Identity Model
public ApplicationUser Artist; //Who Part
public DateTime DateTime { get; set; } //When Part
public string Venue { get; set; } //Where Part
public Genre Genre { get; set; } //Type Part
}
public class Genre
{
public byte Id { get; set; }
public string Name { get; set; }
}
当我创建add-migration CreateAlbum
时,我应该获得两个外键,但我只得到一个,即来自Genre
(Genre_Id
)。
如何解决这个问题?我想将ApplicationUser
(Artist_Id
)即AspnetUser链接到我的Album
表
答案 0 :(得分:1)
您忘了设置获取并设置。在您的类中为Application用户添加get和set。
public class Album
{
public int Id { get; set; }
//ApplicationUser from Asp.net Identity Model
public ApplicationUser Artist { get; set; }; //Who Part
public DateTime DateTime { get; set; } //When Part
public string Venue { get; set; } //Where Part
public Genre Genre { get; set; } //Type Part
}
public class Genre
{
public byte Id { get; set; }
public string Name { get; set; }
}
现在运行迁移。它会起作用。