Note that there are some explanatory texts on larger screens.

plurals
  1. POExtend base type and automatically update audit information on Entity
    primarykey
    data
    text
    <p>I have an entity model that has audit information on every table (50+ tables)</p> <pre><code> CreateDate CreateUser UpdateDate UpdateUser </code></pre> <p>Currently we are programatically updating audit information. </p> <p>Ex: </p> <pre><code> if(changed){ entity.UpdatedOn = DateTime.Now; entity.UpdatedBy = Environment.UserName; context.SaveChanges(); } </code></pre> <p>But I am looking for a more automated solution. During save changes, if an entity is created/updated I would like to automatically update these fields before sending them to the database for storage. </p> <p>Any suggestion on how i could do this? I would prefer to not do any reflection, so using a text template is not out of the question.</p> <p>A solution has been proposed to override SaveChanges and do it there, but in order to achieve this i would either have to use reflection (in which I don't want to do ) or derive a base class. Assuming i go down this route how would I achieve this? </p> <p>For example</p> <pre><code>EXAMPLE_DB_TABLE CODE NAME --Audit Tables CREATE_DATE CREATE_USER UPDATE_DATE UPDATE_USER </code></pre> <p>And if i create a base class </p> <pre><code> public abstract class IUpdatable{ public virtual DateTime CreateDate {set;} public virtual string CreateUser { set;} public virtual DateTime UpdateDate { set;} public virtual string UpdateUser { set;} } </code></pre> <p>The end goal is to be able to do something like...</p> <pre><code> public overrride void SaveChanges(){ //Go through state manager and update audit infromation //FOREACH changed entity in state manager if(entity is IUpdatable){ //If state is created... update create audit. //if state is updated... update update audit } } </code></pre> <p>But I am not sure how I go about generating the code that would extend the interface.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload