2011-11-16 4 views
0

CS. DB Entity Design Existing다중 테이블, 추상 클래스, 엔티티 유형

public abstract class Customer 
    { 
     public int Id { get; set; } 
     public string Name { get; set; } 
     public bool IsCorporate { get; set; } 
    } 

    public class PrivateCustomer: Customer 
    { 
     public string Address { get; set; } 
     public DateTime DateOfContract { get; set; } 
     public int QuoteAmmount { get; set; } 
     public string PromotionCode { get; set; } 
    } 

    public class BusinesCustomer: Customer 
    { 
     public string BusinessName { get; set; } 
     public string BusinessAddress { get; set; } 
     public TypeofContract ContractType { get; set; } 
     public DateTime ContractStart { get; set; } 
     public DateTime ContractEnd { get; set; } 
    } 

    public enum TypeofContract 
    { 
     Hourly =1, 
     Daily = 2, 
     Weekly = 3 

    } 

DB 스토리지 = 몇 가지 예를 보았다 : 그들은이 과정을 수행 한 http://i.msdn.microsoft.com/dynimg/IC315206.gif -> OnlineCourse 및 OnsiteCourse는 그것을위한 C#을 층을 찾을 수 couldnt한다.

어느 것이 든 내가 EF 코드의 첫 번째 접근 방식에서 어떻게 해결해야하는지에 대한 아이디어가 있습니다.

친절한 연락 Vinay.

답변

1

다음은 테이블 머리글을 선언하여 문제를 해결합니다.

public abstract class Customer 
{ 
    public int Id { get; set; } 
    public string Name { get; set; } 
    public bool IsCorporate { get; set; } 
} 

[Table("PrivateCustomer")] 
public class PrivateCustomer: Customer 
{ 
    public string Address { get; set; } 
    public DateTime DateOfContract { get; set; } 
    public int QuoteAmmount { get; set; } 
    public string PromotionCode { get; set; } 
} 

[Table("BusinesCustomer")] 
public class BusinesCustomer: Customer 
{ 
    public string BusinessName { get; set; } 
    public string BusinessAddress { get; set; } 
    public TypeofContract ContractType { get; set; } 
    public DateTime ContractStart { get; set; } 
    public DateTime ContractEnd { get; set; } 
} 

public enum TypeofContract 
{ 
    Hourly =1, 
    Daily = 2, 
    Weekly = 3 

} 
0

내가이 문제를 얻는 방법은

는 추상 클래스를 제거하고 그것을 실체를 확인한 다음 두 엔티티의 threst 하나 mappin에 하나를 사용합니다.

그러나 저장소가 해결되었지만 생성되는 유형의 문제가 해결되지 않았습니다. 당신은 걸을 목록을 얻을 수 없습니다.

은 전문가가이 설명이 링크를 발견 :

http://www.codeproject.com/Articles/100109/Mixing-Table-Per-Hierarchy-and-Entity-Splitting.aspx

을하지만, 내가 어떻게 POCO을합니까. 코드 첫 번째 접근? 아이디어를 환영합니다.

관련 문제