[英]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.