views:

39

answers:

2

Hi!

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. 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.

Since I'm new to EntityFramework I have no idea what's wrong, so came here looking for advise ;)

[UPDATE]

I ran other query on my database:

select * from modelemaster where model_id not in (select model_id from typymaster)

which returns 2000 rows. So there are models that has no types.

[UPDATE]

This is fragment of my .edmx file

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

A: 

What happens when you change the first piece of code with

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

? According to 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.

biozinc
Thank's for reply. it's the same, but I've updated new info. Do you think this might be a problem ;)
Adrian Serafin
A: 

The problem seems to be associated with the wrong EntitySet name.
Please check that you have passed the correct path to Include (maybe pluralization or case sensitivity issue).

Devart
i added fragment of .edmx file to the question. it seems like names are correct
Adrian Serafin