Click here to Skip to main content
16,020,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am using Entity Framework 4.0 and following issue occurs while updating objects (rows) in database:

I have two related tables, say A and B, with A being the master table and B foreign table. Now in my C#.NET application, I make changes from front end and save it.

In save method, I only update those Entity objects whose EntityState is Modified. When I reach Save method, the EntityState of objects of both A and B are Modified. If A's object state is Modified, I attach A's Entity object with EF context, so its state becomes Unchanged (because when an Entity object is attached, its state becomes Unchanged), but as I know it was Modified so I immediately set it to Modified and call context's SaveChanges method.

But the problem occurs now: when I attach A's Entity object to context, EntityState of all related object of type B also becomes Unchanged. So after updating A's object when it reaches to process for B, its EntityState gets Unchanged and so it doesn't update B's objects. Also I have no track of which object of B had state Modified prior attaching A's object.

I need a way that when parent table's entity object is attached to context, it does not attach foreign table's related objects to EF context.

Please provide solution for this. Thanks in advance. :)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900