2012-04-17 3 views
4

포럼의 오랜 시간 숨어있는 사람, MVC Music Store 자습서 (http://www.asp.net/mvc/tutorials/mvc-music-store)를 기반으로하는 질문이 있습니다./mvc-music-store-part-4) 나는 따라하고있다.Entity Framework 코드 첫 번째 ASP.Net 및 DbContext

이 자습서에서는 EF Code First를 사용하여 CE 데이터베이스를 설정합니다. 그러나 앨범, 장르 및 아티스트의 3 가지 모델이 클래스 파일로 있습니다.

using System.Data.Entity; 

namespace MvcMusicStore.Models 
{ 
    public class MusicStoreEntities : DbContext 
    { 
     public DbSet<Album> Albums { get; set; } 
     public DbSet<Genre> Genres { get; set; } 
    } 
} 

왜이 코드에 대한 언급은 말을하지 않습니다 : 읽기

public DbSet<Artist> Artists { get; set; } 

감사를 코드 만 장르 언급과 아티스트 그러나 이제 한 앨범은 많은 예술가를 가질 수 있습니다. 나는 바보가되지 않기를 바란다.

+0

당신은 단지 당신이 직접 조회하고자하는 경우 'DbSet'을 노출 할 필요가 있습니다. – Dismissile

답변

0

앨범은 우리가 앨범으로 아티스트에 액세스 할 수 있습니다에 아티스트가 있기 때문에 :

namespace MvcMusicStore.Models 
{ 
    public class Album 
    { 
     public int  AlbumId  { get; set; 
} 
     public int  GenreId  { get; set; } 
     public int  ArtistId { get; set; } 
     public string Title  { get; set; } 
     public decimal Price  { get; set; } 
     public string AlbumArtUrl { get; set; } 
     public Genre Genre  { get; set; } 
     public Artist Artist  { get; set; } 
    } 
} 
+0

고맙습니다. stackoverflow를 사용하면 제대로 표시 할 수 있는지 확실하지 않았습니다. – Tom

관련 문제