多个表,抽象类,实体类型 [英] Multiple Tables, Abstract class , Entity Types

查看:216
本文介绍了多个表,抽象类,实体类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 Storage =

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

Saw some example : http://i.msdn.microsoft.com/dynimg/IC315206.gif where they have done the Course -> OnlineCourse and OnsiteCourse couldnt find the c# layer for it.

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

any one has any idea on how do i solve this in EF code first approach.

Kind Regards
Vinay。

Kind Regards Vinay.

推荐答案

以下解决方案只是声明一个表头。

The following solves the issue just by declaring a table header.

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

}

这篇关于多个表,抽象类,实体类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆