2016-07-29 10 views
0

私はVS 2013、SQL Server 2008 R2を使用しています。私はちょうどASP.NET MVC & EFを学び始めました。EF6を使用して1つのテーブルに2つの外部キーを作成できません

私は2つのクラスを作成している:私はadd-migration CreateAlbumを作成するとき

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; } 
} 

、私は2つの外部キーを取得する必要がありますが、私は一つだけ、すなわちGenreGenre_Id)から取得しています。

解決方法私は

+1

別の 'テーブル 'を1つの'テーブルアルバム'にマッピングしたいと思います。 – mmushtaq

+0

はい、私はその後、EFで '表Splitting'を使用AlbumTable –

+1

に二つのテーブルすなわちAspnetUser、ジャンルをマップしたい.. [この](http://www.c-sharpcorner.com/UploadFile/ff2f08/table-splitting-in -entity-framework-6-code-first-approach /)と[this](https://msdn.microsoft.com/en-us/data/jj715645.aspx)が参考になります。 – mmushtaq

答えて

1

は、あなたが得る設定し忘れてを設定し、私のAlbumテーブルにApplicationUserArtist_Id)すなわちAspnetUserをリンクさせたいです。クラスを取得し、アプリケーションのユーザーに設定します。

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; } 
} 

移行を実行します。それが動作します。

+0

この時間はありがとう@Amit Kumar –

関連する問題