简体   繁体   English

实体框架ArgumentNullException

[英]Entity Framework, ArgumentNullException

I have database with simple structure: 我有结构简单的数据库:

markimaster(id, name), modelemaster(id, marka_id), typymaster(id, model_id)

I defined relationships between tables and fetch data with this code: 我定义了表之间的关系并使用以下代码获取数据:

ObjectQuery<markimaster> markiQuery = context.markimaster.Include("modelemaster.typymaster");

bindingSourceMarki.DataSource = markiQuery;    

Last line throws ArgumentNullException with ParamName:entity. 最后一行使用ParamName:entity引发ArgumentNullException。 When I change my code to this: 当我将代码更改为此时:

ObjectQuery<markimaster> markiQuery = context.markimaster.Include("modelemaster");

bindingSourceMarki.DataSource = markiQuery;

it work's (means doesn't throw exception), so i thought maybe there is row in typymaster that didn't have coresponding row in modelemaster, but checking database shows nothing. 它的工作(意味着不抛出异常),所以我想也许typymaster中有一行在modelemaster中没有coresponding的行,但是检查数据库什么都没有。

Since I'm new to EntityFramework I have no idea what's wrong, so came here looking for advise ;) 由于我是EntityFramework的新手,所以我不知道出了什么问题,因此来到这里寻求建议;)

[UPDATE] [更新]

I ran other query on my database: 我在数据库上运行了其他查询:

select * from modelemaster where model_id not in (select model_id from typymaster) 从modelemaster中选择*,其中model_id不在其中(从typymaster中选择model_id)

which returns 2000 rows. 返回2000行。 So there are models that has no types. 因此,有没有类型的模型。

[UPDATE] [更新]

This is fragment of my .edmx file 这是我的.edmx文件的片段

EntitySet Name="markimaster" EntityType="MMT_Master.store.markimaster"  store:Type="Tables" Schema="public" 
EntitySet Name="modelemaster" EntityType="MMT_Master.store.modelemaster" store:Type="Tables" Schema="public"
EntitySet Name="typymaster" EntityType="MMT_Master.store.typymaster" store:Type="Tables" Schema="public"

so it seems like names used in path passed to Include are correct 所以似乎传递给Include的路径中使用的名称是正确的

What happens when you change the first piece of code with 当您使用更改第一段代码时会发生什么

bindingSourceMarki.DataSource = markiQuery.Execute(MergeOption.AppendOnly);

? According to MSDN : 根据MSDN

To bind objects to a Windows Form control, set the DataSource property of the control to the EntityCollection or to the ObjectResult that is returned when the Execute method is called on an ObjectQuery object . 要将对象绑定到Windows Form控件,请将控件的DataSource属性设置为EntityCollection 或ObjectResult对象上调用Execute方法时返回的ObjectResult

The problem seems to be associated with the wrong EntitySet name. 该问题似乎与错误的EntitySet名称相关。
Please check that you have passed the correct path to Include (maybe pluralization or case sensitivity issue). 请检查您是否通过了正确的包含路径(可能是复数形式或区分大小写的问题)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 实体框架核心FromSQL引发ArgumentNullException - Entity Framework core FromSQL throws ArgumentNullException Entity Framework Core 控制台应用程序 - 数据库连接生成 ArgumentNullException - Entity Framework Core console app - database connection generates ArgumentNullException 实体框架代码优先:类型类型的计算属性导致Update-Database上的ArgumentNullException - Entity Framework Code First: Computed property of type Type causes ArgumentNullException on Update-Database zzzprojects/entity 框架扩展在 System.Linq.Expressions.Expression.Call 处抛出 System.ArgumentNullException - zzzprojects/entity framework extension throw System.ArgumentNullException at System.Linq.Expressions.Expression.Call CreateDirectConversation / CreateDirectConversationAsync Bot Framework 4中的ArgumentNullException - ArgumentNullException in CreateDirectConversation/CreateDirectConversationAsync Bot Framework 4 ArgumentNullException:值不能为null。 参数名称:实体 - ArgumentNullException: Value cannot be null. Parameter name: entity System.ArgumentNullException:“值不能是 null。 参数名称:实体” - System.ArgumentNullException: “Value cannot be null. Parameter name: entity” 通过 id 获取特定实体的相关项目返回 System.ArgumentNullException - Getting relative item of an specific entity by id returns System.ArgumentNullException 实体框架 - Entity Framework 实体框架中的“不在” - “Not In” in Entity Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM