0

오케스트라 계획 도구에 대한 엔티티 관계 데이터 모델을 개발 중입니다. 최종 결과는 ASP.NET/MVC4 응용 프로그램이어야합니다. 제가 EventComposition 사이 대다 관계가 있음을 시각화하려고 위에다 - 대 - 다 관계 코드를 첫 번째 스타일로 설정하는 방법은 무엇입니까?

Orchestra planning tool E/R diagram

이미지에서 :

이 내 E/R-도의 일부이다. 내 모델에서 나는 EventComposition의 녹음을 저장할 수있는 가능성을 원한다. (다른 이벤트/콘체르토의 매우 다른 녹음 된 버전이 많이있을 수있다.)

public class Composition 
{ 
    public Composition() 
    { 
     Instruments = new Collection<Instrument>(); 
     Events = new Collection<Event>(); 
    } 

    [Key] 
    public int Id { get; set; } 
    public bool Active { get; set; } 

    public string Name { get; set; } 
    public string Description { get; set; } 
    public TimeSpan Durata { get; set; } 

    public virtual Composer Composer { get; set; } 
    public virtual Composer Genre { get; set; } 
    public virtual ICollection<Instrument> Instruments { get; set; } 
    public virtual ICollection<Event> Events { get; set; } 
} 

_

public class Event 
{  
    public Event() 
    { 
     Compositions = new Collection<Composition>(); 
     Members = new Collection<Member>(); 
    } 

    [Key] 
    public int Id { get; set; } 
    public bool Active { get; set; } 

    public string Name { get; set; } 
    public string Description { get; set; } 

    public DateTime StartDate { get; set; } 
    public DateTime EndDate { get; set; } 

    public virtual ICollection<Member> Members { get; set; } 
    public virtual ICollection<Composition> Compositions { get; set; } 
    public virtual Calendar Calendar { get; set; } 
    public virtual EventType EventType { get; set; } 
    public virtual Location Location { get; set; } 
} 

내 질문 : 내 코드에서 할 다음

내가 (내 코드 첫 번째 데이터 모델에 대한 관련 코드) 지금까지 한 일이다 관계 특성 "녹음"을 추가합니까?

편집 : 링크 테이블을 만들어야합니까, 아니면 더 좋은 대안이 있습니까?

답변

1

달성하려는 것은 특성이있는 다 대다 관계입니다. 관계형 데이터베이스에서 N 대 M 관계를 모델링하려면 항상 중간 테이블이 필요합니다. EF와 함께 속성을 추가하려면 관계를 모델링하고 올바르게 매핑 할 다른 엔티티가 필요합니다. 이 질문에서 어떻게하는지 설명합니다 :

Entity Framework Code 1st - Mapping many-to-many with extra info

+0

링크 Thx. 나는 이것을 답으로 표시하기 전에 몇 가지 테스트를해야한다. –

+0

답변 틱을 주셔서 감사합니다. – Tasio