Entity Framework 4 Entity with EntityState of Unchanged firing update
        Posted  
        
            by Andy
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Andy
        
        
        
        Published on 2010-05-28T18:39:53Z
        Indexed on 
            2010/06/03
            18:34 UTC
        
        
        Read the original article
        Hit count: 250
        
entity-framework
I am using EF 4, mapping all CUD operations for my entities using sprocs.
I have two tables, ADDRESS and PERSON. A PERSON can have multiple ADDRESS associated with them.
Here is the code I am running:
Person person = (from p in context.People
                             where p.PersonUID == 1
                             select p).FirstOrDefault();
Address address = (from a in context.Addresses
                               where a.AddressUID == 51
                               select a).FirstOrDefault();
address.AddressLn2 = "Test";
context.SaveChanges();
The Address being updated is associated with the Person I am retrieveing - although they are not explicitly linked in any way in the code. When the context.SaveChanges() executes not only does the Update sproc for my Address entity get fired (like you would expect), but so does the Update sproc for the Person entity - even though you can see there was no change made to the Person entity.
When I check the EntityState of both objects before the context.SaveChanges() call I see that my Address entity has an EntityState of "Modified" and my Person enity has an EntityState of "Unchanged".
Why is the Update sproc being called for the Person entity? Is there a setting of some sort that I can set to prevent this from happening?
© Stack Overflow or respective owner