In the above code the CreatedBy, CreatedOn, UpdateBy and UpdatedOn properties are automatically updated every time a record is modified or UpdateBy and UpdatedOn are modified when a record is updated.
What about the Delete operation?
I am getting an error there trying to apply the same idea as in your post.
"The object is in a detached or deleted state. An ObjectStateEntry in this state cannot be modified."
Hi Yitzhak, in Linq to SQL you have the DeleteCustomer(Customer instance) which you can override you could then pass the info you want into a sproc that does the delete or as I thin you intend just mark as deleted.
We are using Entity Framework (not the LINQ to SQL) for ASP.NET Dynamic Data plus stored procedures. So I have to pass somehow a User name as a parameter to a stored procedure. For the obvious reasons the User name is not exposed to the user interface (UI).
- logical delete, this is where you must have a stored proc and user name as a parameter.
- stored procedure which accepts an arbitrary parameter which in turn is not mapped to an Entity.
Do you have any idea what could be done with the current limitations of the EF v.1 upon us?
I would ask this question on EF forums. be specific (don't mention DD) just about passing username to SPROC for logical delete.
Exactly what I was looking for! Thanks.
I'm doing pretty much the same sort of thing. However I don't want a dependency upon HttpContext in my model code - it should be able to run in any context (e.g. unit tests). So I'm setting a currentUser property on the ObjectContext on creation and then accessing that from the OnSavingChanges method.
I'm using EF4, but I don't find a good solution. I tried to set the Object to the OrginalValiues, but they are not available if the deletion is executed.
I think the easiest way ist to implement a own update, wich sets the flag.