Set the value of a column only when inserting, don not allow update RRS feed

  • Question

  • Hi,

    My current specifications require exposing the L2S objects through a WCF Service, so I enabled SerializationMode = Unidirectional. That adds the DataContract and DataMember attributes to all objects and properties.

    Also, I don't care about concurrency so I set all columns to UpdateCheck = never.

    I have a column "ExpirationDate" in one of my tables that can only be set by the service caller when the record is inserted. From that point and on that column is considered read only and can not be updated under any circumstances.

    The problem is I haven't found a way to force such behavior. I already tried the ReadOnly property but it has no effect in my case because of the SerializationMode.

    I've noticed the update sentence generated by L2S always includes the ExpirationDate column. That's very dangerous in my scenario since the service caller might change the value (inadvertently or not), and the original value will be overwritten in the database.

    Any ideas?

    Saturday, August 21, 2010 11:12 PM


All replies

  • Hi Oscarmorasu,

    I am looking at your problem and will get back to after some research.


    Jay [MSFT]


    Monday, August 23, 2010 10:16 PM
  • Oscarmorasu,

    I guess the problem here is two folded.

    1. You need to have your column un-updatable/deletable after first insert.

    2. After the column is set as un-apdatable you need to send updates to other colums in the same row.

    1 --> can be achived by simply denying update and delete permission on the column.

    2 --> can be achieved by using DataContext.ExecuteCommand

    Executes SQL commands directly on the database

    Let  me know if this helps



    Wednesday, August 25, 2010 2:45 AM
  • Thanks for the answer Jay,

    Point 2) is exactly what I need. I'll have to execute the update command myself during the OnUpdate, or use a stored proc for the Update operation.

    Wednesday, August 25, 2010 11:41 PM
  • Oscarmorasu, Sounds great. And thank you for the reply. Let us know if this thread can be marked answered!!

    ~Jay [MSFT]

    • Proposed as answer by Jay.Akhawri Friday, August 27, 2010 4:35 PM
    Friday, August 27, 2010 4:35 PM