Entity Framework: Manually Changing Object Status Values

I use EF5 in a disabled way. I have a main table called Cases with lookup tables for different things with specific associations. For example, the SOURCE_ID column is associated with the Sources table, where this table contains search queries.

Essentially for Cases , I have a Source_ID column, as well as an association and navigation property called Source , to navigate to the linked table.

Since I use things in disconnected mode, when I want to save an object, I manually set the state from Added to Modified . This works well (following some examples in Julia Lermon's book).

What happens is that if I changed the SOURCE_ID column to a different value and the related table was loaded by the entity, when I changed the state to Modified , SOURCE_ID will revert to the original value, presumably due to association.

I am loading the linked Sources table because I want to display other things from this table, but I just want to change the SOURCE_ID and save it. It doesn't seem to like it.

Any thoughts?

+4
source share
1 answer

More code is required, but I will take a picture.

Instead of just updating SOURCE_ID, try updating the source search link.

So, instead of ....

 Case.Source.ID = 1; 

May be....

 Case.Source = db.Sources.Where(x => x.SOURCE_ID == 1).FirstOrDefault(); 

(edit: oh, was that asked a month ago? oops. well, still.)

0
source

All Articles