0
表有类似但不相关的数据记录实体框架6类映射到表中的列基于值
+------------+------------+-----------+-------------+----------------------+
| RecordType | Name | Surname | DateOfBirth | DateOfIncorporation |
+------------+------------+-----------+-------------+----------------------+
| Person | Luke | SkyWalker | 1/1/1017 | |
| Company | Jedi Order | | | 1/1/101 |
+------------+------------+-----------+-------------+----------------------+
我想用两个类来处理这个问题,而不必总是看RecordType(个人或公司)。
这是一个现有的表并没有在分裂表二的选项(讽刺的是,该表是使用代码第一实体框架创建的,但是该表现在不能被修改)
是否有一个我可以在实体框架中做到这一点?
也就是说,当我使用Person class (context.Persons)
我只能取得记录类型的“人”,当我使用Company class (context.Companies)
我只能取得记录类型“业公司”记录的记录 -
class Person
{
string RecordType {get;set;} //This will only have "Person"
string Name {get;set;}
string Surname {get;set;}
DateTime DateOfBirth {get;set;}
}
class Company
{
string RecordType {get;set;} //This will only have Company
string Name {get;set;}
DateTime DateOfIncorporation {get;set;}
}
这非常有帮助 - 谢谢! – Looking4Answers
这种方法确实需要修改表,因为我明白OfType会创建一个鉴别器(有没有一种方法可以通过Fluent API配置鉴别器?)。但最大的帮助是我不必拆分表格。 – Looking4Answers
我在上面提供的链接中搜索并找到了关于更改鉴别符的一些信息([link](https://weblogs.asp.net/manavi/inheritance-mapping-strategies-with-entity-framework-code-first- ctp5-part-1-table-per-hierarchy-tph)) - 会试试这个。再次感谢你 !! – Looking4Answers