首页 > 解决方案 > 实体框架在运行时选择子类

问题描述

我的结构如下

public class Mammal
    {
        public string Name { get; set; }

        public string PrintName()
        {
            return "The name is " + Name;
        }
    }

    public class Dog : Mammal
    {
        public string Breed { get; set; }

        public new string PrintName()
        {
            return "The name is " + Name + " and i go woof woof";
        }
    }

在基于属性的运行时,我从实体框架中选择数据,并希望基于变量返回正确的子类型。

如何指定在我的实体框架选择查询中使用哪个子类?

标签: c#entity-frameworkgenerics

解决方案


推荐阅读