Linq to SQL - Failing to update

后端 未结 2 1823
天涯浪人
天涯浪人 2020-12-19 05:58

I\'m having some troubles with updating linq to sql entities. For some reason, I can update every single field of my item entity besides name.

相关标签:
2条回答
  • 2020-12-19 06:04

    It sounds like your DBML might be out of synch. You should delete the tables and re-add them and try and run it again.

    Just delete your Items table manually and re-add it.

    EDIT: Based on your edit, you should check out the following thread regarding GetHashCode.

    http://social.msdn.microsoft.com/forums/en-US/linqtosql/thread/6cc6c226-f718-4b22-baad-dba709afe74b/

    .Net rules claim that GetHashCode() and Equals() must always be implemented in tandem. Two objects that are equal must have the same hash code.

    Also, the combination of GetHashCode() + Equals() forms the entity's concept of identity. If you make it based on field values (other than PK) then the identity changes as you change the fields. This is bad if L2S must lookup other info in a dictionary based on the entity's identity, and especially if L2S needs to find an entity in its identity cache!

    Advice: don't change the identity of an entity. L2S expects it to be based on the object's natural (address based) identity.

    0 讨论(0)
  • 2020-12-19 06:27

    It appears that the SQL being generated is not including the contents of the SET clause (notice that there is no [Name] = @pXX after SET). Are all of the properties (data type, size, etc.) of the entity field set correctly in the dbml designer?

    0 讨论(0)
提交回复
热议问题