2012-01-30 3 views
0

나는 매우 단순한 클래스 구조를 가지고 있다고 말하면서 무엇보다 편리함을 제공합니다. Entity Framework 4의 클래스 구성

class A{ 
    [Column("someValue")] 
    public int someValue{get; set;} 
} 

[Table("tableB")] 
class B{ 
    [Column("somethingElse")] 
    public int somethingElse{get; set;} 
    public A somethingEncapsulated{get; set;} 
} 

[Table("tableC")] 
class C{ 
    [Column("otherSomething")] 
    public int otherSomething{get; set;} 
    public A somethingEncapsulated{get; set;} 
} 

그리고을 변경할 수 없습니다 데이터베이스 구조,

tableB 
------ 
somethingElse int 
someValue int 

tableC 
----- 
otherSomething int 
someValue int 

는 클래스 A를 제거하지 않고 엔티티 프레임 워크에서이 구조를 표현하는 것이 가능하므로 보인다? 그렇다면 어떻게?

+0

당신은 클래스 A'를 제거하지 않고'무엇을 의미합니까? –

+1

다른 대안은 클래스 B와 클래스 C에서 클래스 A를 상속하는 것입니다. 그런 다음'Table per hierarchy ','table per type'과 같은 여러 매핑 옵션을 가질 수 있습니다. http://bancentlauzon.wordpress.com/2011/04/19/entity-framework-4-1-inheritance-7/ –

+0

@Jayantha, 상속은 내가 ​​생각했던 방식이 아닙니다. 그것은 효과가 있을지 모르지만 마음에 떠오르는 첫 번째 관심사는 "B is a"라고 말하는 것이 적절하다는 것입니다. B가 이미 다른 클래스,보다 적절한 클래스로부터 상속 받고 있다면? – MushinNoShin

답변

2

이 시나리오에서는 복합 유형 매핑을 사용할 수 있습니다.

[ComplextType] 
public class A{ 
    [Column("someValue")] 
    public int someValue{get; set;} 
} 

Go through this article

관련 문제