Entity Framework question

  • Thread starter Thread starter Nick
  • Start date Start date
N

Nick

Hello,

Dumb question time. I'm populating a datagridview using the entity
framework. I've got a parent/child relationship (one to many). When I insert
new records into the datagridview to add child records the records are
inserted, but the foreign key is null. What do I need to do to properly
insert the records?

Thanks for any help, I really appreciate it.

Thanks,
Nick
 
Nick said:
Hello,

Dumb question time. I'm populating a datagridview using the entity
framework. I've got a parent/child relationship (one to many). When I
insert
new records into the datagridview to add child records the records are
inserted, but the foreign key is null. What do I need to do to properly
insert the records?

What is the statement you are using to pull the data? What are you talking
about loading into the grid only child entities or what?
 
Thanks for the reply. Sorry for not being clear. I'm loading only the child
records into the grid. The statement is very basic, something like "from c in
_context.child_record select c"

Thanks.
 
Nick said:
Thanks for the reply. Sorry for not being clear. I'm loading only the
child
records into the grid. The statement is very basic, something like "from c
in
_context.child_record select c"
Are you actually doing something in a foreach loop and looking at the field
in question to see that the data is not there? I find it hard to believe
that the constraint key of the parent entity is not present in the child?
 
Mr. Arnold said:
Are you actually doing something in a foreach loop and looking at the field
in question to see that the data is not there? I find it hard to believe
that the constraint key of the parent entity is not present in the child?
If I use a foreach loop would it update automatically? I'm setting the
datasource:

var results="from c in_context.child_record select c";
datagridview1.DataSource=results;

Thanks for your help.
 
Nick said:
If I use a foreach loop would it update automatically? I'm setting the
datasource:

var results="from c in_context.child_record select c";
datagridview1.DataSource=results;

No, I am saying do this.

foreach (var result in results)
{
string data = result.field;
}

Put the solution in the IDE in debug mode and single step in the for loop
and look at the data in the field in question.
 
Back
Top