【发布时间】:2013-12-17 14:41:56
【问题描述】:
我在我的应用程序中使用 Entity Framework 4。例如,我有一组简单的实体:
订单:Id、代码、名称、StatusId、SectorId
部门:ID、名称、代码
状态:ID 名称、代码
我必须从 xls 将数据加载到表 Orders 中,它的结构如下:代码(订单)、名称、代码(扇区)、代码(状态)。 因此,对于外键,我必须按代码查询外键 id(用于扇区和状态),然后分配给 SectorId 和 StatusId; 我有几十个字段的大表。所以我不想手动设置每个字段。 如果我知道 xls 的结构,我可以创建一个字典 Dictionary,其中键是字段的名称(在 Orders 表中),值是 xls 中列的索引。 所以我喜欢有类似的东西
foreach(var item in Dictionary)
{
///Determine if the field is Foreign key for Entity Order (for example in ObjectContext) using GetType().GetProperty().GetValue.... or something
// If so query ObjectContext for the id of the entity that is foreign key using a value of Code from xls.
}
是否有可能实现以及如何实现?请帮忙!
【问题讨论】:
标签: c# entity-framework-4