实体框架多列映射

时间:2015-10-28 06:38:41

标签: c# entity-framework entity-framework-6

我试图实现数据库结构,其中有一些公共字段我将它们放在一个单独的抽象类中,但我想知道3个类是从同一个抽象类继承而2个是否具有相同的属性名,所以,通过默认实体框架将在数据库中添加数字后跟属性名称。有没有办法单独实现这个。我研究过复杂的类型,并通过互联网搜索,但无法找到任何灵活的解决方案。我分享了我的代码,请指导我

public abstract class GenericImpression
    {
        [Key]
        public int ImpressionId { get; set; }

        public DateTimeOffset ReportingDate { get; set; }
    }


public class Impression : GenericImpression
    {       
        public string InventorySource { get; set; }
        public string Media { get; set; }
    }

public class Impression21 : GenericImpression
        {       
            public string InventorySource { get; set; }
        }

现在,EF将添加一个包含InventorySource1和InventorySource Column的表。

1 个答案:

答案 0 :(得分:0)

使用OfType<>。 例如:

_context.GenericImpressions.ofType<Impression21>().ToList()
相关问题