문제

EF 4.0 코드 만 사용하여 초록 클래스와 일반 클래스를 연결하고 싶습니다.

클래스 '항목', 'Contentbase'및 'Test'가 있습니다.

'Contentbase'는 추상적이며 '테스트'는 그것에서 파생됩니다.

'Contentbase'에는 '항목'인스턴스에 연결되는 속성 '항목'이 있습니다.

따라서 'test.item'또는 'contentbase'에서 파생 된 클래스에는 '항목'내비게이션 속성이 있습니다.

내 DB에서 테스트를위한 모든 레코드에는 항목에 대한 레코드가 일치합니다.


public class Item
{
    public int Id { get; set;}
}

public abstract class ContentBase
{
    public int ContentId { get; set;}
    public int Id { get; set;}

    public Item Item { get; set;}
}

public class Test : ContentBase
{
    public string Name { get; set;}
}

이제 일부 Init Code

public void SomeInitFunction()
{

    var itemConfig = new EntityConfiguration<Item>();
    itemConfig.HasKey(p => p.Id);
    itemConfig.Property(p => p.Id).IsIdentity();
    this.ContextBuilder.Configurations.Add(itemConfig);

    var testConfig = new EntityConfiguration<Test>();
    testConfig.HasKey(p => p.ContentId);
    testConfig.Property(p => p.ContentId).IsIdentity();

    // the problem 
    testConfig.Relationship(p => p.Item).HasConstraint((p, q) => p.Id == q.Id);

    this.ContextBuilder.Configurations.Add(testConfig);  
}

오류가 발생합니다. 키는 파생 유형 '테스트'에 등록됩니다. 키는 루트 유형 'Contentbase'에 등록되어야합니다.

어쨌든 나는 오류가 발생합니다. IA는 무엇을 잘못하고 있습니까?

도움이 되었습니까?

해결책

지금까지 결론 : 불가능합니다.

다른 팁

SupperType 엔티티에서 당신의 관계를 재정의하기 위해 시도하십시오.

Contentbase : Public Virtual Item item {get; 세트;}

테스트 : 공개 새 항목 item {get; 세트;}

이것은 내 테스트 프로젝트에서 컴파일되었지만 더 이상 테스트하지 않았습니다. 당분간, wheb ef5 또는 최종 Comeso

내비게이션 속성 항목은 기본 유형 레벨에서 정의되므로 모델은 기본 유형을 알고 있습니다. 항목 속성을 전달하고 관계에 매핑하는 테스트 클래스에 속성을 추가 할 수 있습니다.

public class Test : ContentBase
{
    public string Name { get; set;}
    public string TestItem { get {return Item;} ...

}

testConfig.Relationship(p => p.TestItem )
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top