Updating Primary Key and avoiding Invalid Operation Exception RRS feed

  • Question

  • In my application there is a requirement to update the primary key of an object.  Every time I try to do this I receive an Invalid Operation message saying basicly - create a new object and deletet the current one.  That means in most scenarios, I will need to do the following: create a new object and link all of the depended objects to this new object and then delete the old object. 


    All of my objects have additional columns for object identity and version. I also have a common base class for all of my objects. Is there a way to override Ling to SQL's behavior of using the primary key fields for identity to using my object identity and version fields? 







    Thursday, November 13, 2008 12:54 PM


All replies

  • L2S just uses the terminology of primary key to refer to the identity of the object, since this is most often the case. You can change the PK info in the mapping to refer to your identity field. However, L2S still requires that your object's identity does not change, so don't include a version field with it.

    Thursday, November 13, 2008 4:02 PM
  • Thanks Matt - That seems to work in the testing I've done so far.


    Friday, November 14, 2008 7:33 PM