MvcMusicStoreの例でEntity Frameworkの代わりにFluent NHibernateを使用しようとしていますが、Createを使用してArtistIdとGenreIdに入力して問題が発生しています表示します。以下のように見えるコントローラにメソッドを作成します
MVCでFluent NHibernateを使用してCreateビューのオブジェクトをマップする
public class AlbumMap:ClassMap<Album>
{
public AlbumMap()
{
Id(x => x.AlbumId);
Map(x => x.AlbumArtUrl);
References(x => x.Artist).Cascade.All().Column("ArtistId");
References(x => x.Genre).Cascade.All().Column("GenreId");
Map(x => x.Price);
Map(x => x.Title);
}
}
:私は私のアルバム地図で
私は他のオブジェクトを参照しています、事実とは何かだと思うpublic ActionResult Create()
{
MusicRepository repository = new MusicRepository();
ViewBag.ArtistId = new SelectList(repository.GetArtists(), "ArtistId", "Name");
ViewBag.GenreId = new SelectList(repository.GetGenres(), "GenreId", "Name");
return View();
}
と問題が発生しているCreateビューの部分は次のとおりです。
<div class="editor-label">
@Html.LabelFor(model => model.Genre, "Genre")
</div>
<div class="editor-field">
@Html.DropDownList("GenreId", String.Empty)
@Html.ValidationMessageFor(model => model.Genre)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Artist, "Artist")
</div>
<div class="editor-field">
@Html.DropDownList("ArtistId", String.Empty)
@Html.ValidationMessageFor(model => model.Artist)
</div>
データベースでは、新しいアルバムを作成した後、TitleやAlbumUrlなどの他のフィールドは入力されますが、ArtistIdとGenreIdはnullに設定されます。