简体   繁体   English

首先使用Entity Framework代码将2个相关实体合并到1个表中

[英]2 related entities into 1 table using Entity Framework code first

I have two classes. 我有两节课。 Foo and FooSettings. Foo和FooSettings。

Foo
- Id
- Name
- Settings

FooSettings
- ShowName
- Discount

And I would like to have a single table in the DB that looks as follows: 我想在数据库中有一个表,如下所示:

Foo
- Id
- Name
- Settings
- SettingDiscount
- SettingShowName

The example is quite simple and probably should collapse Foo and FooSettings into a single object as well. 该示例非常简单,可能还应该将Foo和FooSettings折叠到单个对象中。 Our real scenario has quite a few more fields. 我们的实际场景还有更多领域。 I think what I have done is organized my entities into bounded contexts (correct me if I am wrong) 我认为我所做的是将我的实体组织到有限的上下文中(如果我错了,请纠正我)

I would like to keep those two objects (unless I am completely wrong and there is a better way to do this) but I would like them to map onto a single table in the DB because it is a 1 to 1 relationship. 我想保留这两个对象(除非我完全错了,并且有更好的方法可以这样做),但是我希望它们映射到DB中的单个表,因为它是一对一的关系。

Is it possible to do this using Entity Framework v5.0 code first. 是否可以先使用Entity Framework v5.0代码执行此操作。

尝试按此处所述进行表拆分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 实体框架代码优先多对多不使用 GUID 加载相关实体 - Entity Framework Code First Many-To-Many not loading related entities using GUID 使用实体框架代码优先方法,如何创建一个具有相关实体列表作为子属性的实体? - Using Entity Framework Code First approach, how do I create an entity that has a list of related entities as a child property? 表拆分实体框架代码优先-3个以上实体 - Table Splitting Entity Framework Code First - 3+ Entities Entity Framework Code First - 从表中删除相关项 - Entity Framework Code First - Delete related items from a table 使用分离的实体首先在Entity Framework 5中使用代码进行更新 - Updating using code first in Entity Framework 5 with detached entities 使用linq和相关实体查询实体框架7 - Query to entity framework 7 using linq and related entities 如何使用实体框架代码优先从数据库中删除所有相关实体 - How to delete all related entities from database with Entity Framework code-first 实体框架代码优先-相同类型的2个实体 - Entity Framework Code First - 2 Entities of the Same Type 实体框架代码优先和链接实体 - Entity Framework Code First and linked entities 过滤相关实体或导航属性,其中实体框架 6 中有连接表 - Filter related entities or navigation property where there is a join table in Entity Framework 6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM