我已经使用TPH来创建表的特殊实例,即。
section <- introduction-section
有许多不同的部分类型即结论
section <- conclusion-section
我需要实例化这些类的新对象,如果没有TBH,我会:
var myNewSection = new section();
但是我使用TBH所以我需要实例化子实体,以便正确填充鉴别器:
myNewSection = new I_Section(); db.Section.AddObject(myNewSection);
然而,这会产生一个问题,我必须明确引用TBH实体,即I_Section,并在循环中有一个switch语句。
有没有办法在运行时定义这个类,即I_Section,比如说我可以从循环中的其他值构造一个字符串?
String strSectionCode = "I"
string strFullName = strSectionCode + "_" + "Section";
var myNewSection = new strFullname ??? () // I know this is not possible, but it shows where I am trying to get to.
提前致谢。