简体   繁体   中英

2 related entities into 1 table using Entity Framework code first

I have two classes. Foo and 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. 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.

Is it possible to do this using Entity Framework v5.0 code first.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM