Reputation: 27224
I'm using Entity Framework and was wondering what the easiest way to save a LastModified
date field in the database alongside user details (Active Directory).
I first thought of using a Database Trigger to update the field, but I don't think there's any way to retrieve the authenticated user in order to identify them to that record.
Upvotes: 3
Views: 104
Reputation: 44941
If the authenticated user is actually the user that the actions are performed on behalf of in SQL Server, you can actually get the current user using the builtin function SYSTEM_USER or CURRENT_USER in a trigger.
For example:
UPDATE (appropriate table name)
SET LastModified = GETDATE(),
LastModifiedBy = SYSTEM_USER
WHERE (appropriate where clause)
Upvotes: 1