0

본인에게는 링크 및 콘텐츠, 뉴스 요소가 있습니다.EF 핵심 속성 하위 값 추가시 열 설정

**Link**: Id, Url, RowId, Discriminator 
**Content**: Id, Text, Link 
**News**: Id, Date, Text, Link 

새 콘텐츠 나 뉴스를 추가 할 때 자동으로 RowId를 삽입 ID로 설정합니다. Link.Url을 통해 해결 엔티티를 해결해야합니다.

그래서 Link.Discriminator와 Link.RowId가있는 경우 Id가 필요한 엔티티 (컨텐츠 또는 뉴스)를 확인할 수 있습니다.

해결 방법을 알려주세요.

+0

예를 들어 URL 해시를 계산하고 명시 적으로 링크 ID에 할당하려 했습니까? –

+0

질문이 Content/News => RowId를 Link.RowId에 지정하는 것과 관련이 있는지 또는 RowId 및 Discriminator를 기반으로 관련 데이터 컨텐츠/뉴스를로드하는 방법인지 여부는 확실하지 않습니다. –

답변

0

내가 이해하는 한, 이것은 대략 당신이 쫓고있는 것입니다.

public void AddContent(string Text, string Link) 
{ 
    var content = new Content { 
     Text = Text, 
     Link = Link 
     }; 

    //The id is collected when you add the Entity to the context 
    dbContext.SaveChanges(); 

    dbContext.Link.Add(new Link { 
     Url = <whatever>, 
     RowId = content.Id, 
     Discriminator = "Content" 
    }); 

    dbContext.SaveChanges(); 
}