none
EF Current User and Record Date RRS feed

  • Question

  • Hi

    I have a requirement that goes like this:

    Every entity(and table) in the model has a current userID and RecordDate that indicates the last INSERT\UPDATE user id and operation date.

    What is the best approach to set this automaticly wihtout setting this properties everytime the developer uses and entity?

    I am using a repository pattern with unit of work.

    Thanks


    Jorge Vinagre

    Monday, June 11, 2012 2:58 PM

Answers

  • Hi Jorge Vinagre,

    Welcome to MSDN Forum.

    I think we can create a trigger in the database, everytime we do insert or update in the database, updating the userID column and RecordDate column. But I'm not sure why you want to change 'userID', commonly, it should be an identity column and never to be changed.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, June 12, 2012 2:44 AM
    Moderator

All replies

  • Hi Jorge Vinagre,

    Welcome to MSDN Forum.

    I think we can create a trigger in the database, everytime we do insert or update in the database, updating the userID column and RecordDate column. But I'm not sure why you want to change 'userID', commonly, it should be an identity column and never to be changed.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, June 12, 2012 2:44 AM
    Moderator
  • Hi Jorge Vinagre,

    Welcome to MSDN Forum.

    I think we can create a trigger in the database, everytime we do insert or update in the database, updating the userID column and RecordDate column. But I'm not sure why you want to change 'userID', commonly, it should be an identity column and never to be changed.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    I there

    I dont mean changing it on the Users table i mean in the other business tables because the records are inserted or updated by app users. These columns are audit columns.

    Thanks


    Jorge Vinagre

    Wednesday, June 13, 2012 10:19 PM
  • Hi Jorge Vinagre,

    I suggest to create a trigger in the database, not in the client. We can insert records into audit table when the trigger is fired.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, June 14, 2012 5:31 AM
    Moderator
  • Hi Jorge Vinagre,

    Any update about this issue? If you need further help, please feel free to let me know.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, June 20, 2012 8:05 AM
    Moderator