Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法将EF实体集添加到字典_C#_Entity Framework_Inheritance - Fatal编程技术网

C# 无法将EF实体集添加到字典

C# 无法将EF实体集添加到字典,c#,entity-framework,inheritance,C#,Entity Framework,Inheritance,我正在尝试将EF实体集添加到字典中,如下代码所示: private static readonly Dictionary<string, ObjectSet<EntityObject>> Gateways = new Dictionary<string, ObjectSet<EntityObject>> { {"PlanSection", ModelEntities.PlanSection} }; 您有两个不同的对象 MathA

我正在尝试将EF实体集添加到字典中,如下代码所示:

private static readonly Dictionary<string, ObjectSet<EntityObject>> Gateways 
    = new Dictionary<string, ObjectSet<EntityObject>>
{
    {"PlanSection", ModelEntities.PlanSection}
};

您有两个不同的对象

MathApplication.Models.PlanSection


检查您的代码并在两侧使用适当的单个对象。

您真的需要字典来包含对象集吗,或者在字典中包含实体列表就足够了

如果实体列表足够了,那么为什么不将成员设置为IEnumerable,然后添加为值ModelEntities.PlanSection.LoadAll()或其他内容呢

如果您的目的是让所有对象集在该字典中统一,那么请尝试创建一个将由所有实体实现的接口,然后将字典的值类型设置为类似IEnumerable的值


或者,另一种方法是尝试创建一个以动态类型为值的字典,然后编译器会让你一个人呆着,我想,但是,在使用字典中的值时,您将遇到其他问题,因为您必须强制转换这些值才能在设计时访问属性。

所有这些类都是由
EntityFramework
生成的。我可以编辑它们,但它们将在下一次模型更新时重新生成它们被定义为分部类,因此在该项目中,您可以创建具有相同名称和分部关键字的类,并实现附加逻辑(如实现接口),这些类将不会被覆盖。
public partial class PlanSection : EntityObject
MathApplication.Models.PlanSection
System.Data.Objects.DataClasses.EntityObject