多个表,抽象类,实体类型

时间:2011-11-16 22:32:01

标签: entity-framework-4 entity-framework-4.1

CS。

    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 Storage = DB Entity Design Existing

看了一些例子:http://i.msdn.microsoft.com/dynimg/IC315206.gif他们在那里完成了课程 - > OnlineCourse和OnsiteCourse无法找到它的c#层。

任何人都知道我如何在EF代码第一种方法中解决这个问题。

亲切的问候 维奈。

2 个答案:

答案 0 :(得分: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

}

答案 1 :(得分:0)

我解决这个问题的方法是

删除抽象类,并使其成为一个实体,然后使用一对一的映射来获取两个实体的数量。

但是存储问题仍然解决了它所创建的类型的问题。你无法得到一份清单。

找到了这个大师解释这个链接的链接:

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

但我怎么做POCO。代码第一种方法? 欢迎任何想法。