- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
尝试为我正在制作的系统实现一个非常简单的 TPH 设置,1 个基础类,2 个继承类。
但是继承的类都属于同一个实体集,所以在我的 ObjectContext using 循环中,我只能访问基本抽象类。我不太确定如何获得具体类的元素? (我也将其转换为使用 POCO)。
然后在我的应用程序中使用实体:
using (SolEntities sec = new SolEntities()) {
Planets = sec.CelestialBodies;
}
在 sec
上设置了一个 CelestialBodies 实体,但没有我预期的行星/卫星。
不太确定需要做什么才能访问它们。
谢谢
最佳答案
您可以使用OfType
方法:
using (SolEntities sec = new SolEntities()) {
Planets = sec.CelestialBodies.OfType<Planet>();
}
关于c# - EF TPH 继承查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4578598/
我有一个表用于存储 TPH 配置中的几个继承实体。这很好用,没有任何问题。我面临的问题是我需要使用附加字段扩展其中一些实体,并希望使用 TPT 将这些新字段存储在它自己的表中。 为了说明一些背景,我会
首先,这些问题很相似但绝对不一样: Can I mix Table per Hierarchy and Table per Type in Entity Framework? - 指的是不同的场景。
您好,我正在使用 TPH 继承来建立类似的可配置项。我的 TPH 模型是: public class baseConfigItem { public int ID {get;
实体 public abstract class Person { public string FirstName { get; set; } public string LastName {
在我的项目中,我使用 Entity Framework core 2.0。下一个代码稍微简化了。有这样的模型: public class Site { public int Id { get;
我有以下数据库模式: 我正在使用 Table-per-Hiearchy (TPH) 继承。案例表的“类型”字段确定案例是电子邮件案例还是推特案例。它们都与 Cases 表是 1:N 关系。 我在 EF
尝试为我正在制作的系统实现一个非常简单的 TPH 设置,1 个基础类,2 个继承类。 但是继承的类都属于同一个实体集,所以在我的 ObjectContext using 循环中,我只能访问基本抽象类。
我有一张 table : Groups - Id - Name - Type 这张表是一组产品、客户或供应商。要对产品进行分组,我需要在类型列中使用“P”,对客户和供应商进行分组,我需要分别使用
我有一个 wpf 应用程序,其中包含一个首先使用实体框架代码制作的数据库。 我有一个类 Shoes.cs 和两个继承自鞋子的类:Canvas.cs 和 Boots.cs 对于映射,我使用了 tph
背景 我正在使用 .NET Framework 3.5 SP1 在 Visual Studio 2008 SP1 中使用 ADO Entity Framework 编写数据访问库。我正在尝试在两个都派
我将 Entity Framework 6.0.2 与现有数据库一起使用,其中标签存储在单个表中,如下所示: Id: int, 主键 TagType:字符串,判断标签的类型,“usertag”或“mo
我收到错误消息;错误 3032:从第 77 行开始映射片段时出现问题:映射条件成员“Company.CompanyTypeId”,其条件不是“IsNull=False”。删除 Company.Comp
我已经使用 THP 实现了具有简单继承的代码优先数据库架构: 而且我需要查询所有类型的所有通知。NotificationUser 表中的 TargetUser 属性是一个关联。我正在尝试执行下一个代码
我使用的数据结构与此类似,其中动物类型由表中的鉴别器列确定: public class Farm { public int Id { get; set; } public virtua
我将实体配置为始终使用属性“DELETED”='N'进行查询。在 EF 6 中,我可以这样做: modelBuilder.Entity().Map(m => m.Requires("DELETED")
我有一个关于 EF6 的问题。假设我有一个如下所示的抽象基类: [Table("Persons")] public abstract class Person { [Key] publ
我是第一次在 C# MVC 中设置 TPH 继承,我对如何将子类值映射到表有点困惑。例如,我的父实体的流畅 map 是使用以下方式声明的: public class ProjectTaskMap :
我想使用 Mapping Properties of an Entity Type to Multiple Tables in the Database (Entity Splitting)同时使用
可能问题的标题不是不言自明的。 我有一个带有 Entity Framework 6 的 ASP.NET MVC5 项目。我首先使用代码,并且我已经为一个实体实现了 TPH 模式。 有一个基本的请求实体
给定以下类结构 public class Parent { public Guid Id { get; public List Children { get;
我是一名优秀的程序员,十分优秀!