For an ASP.NET MVC application that I'm developing, my entities are going against pre-existing tables that have columns designed to track database transactions (LastModDate, LastModByUserId, CreateDate,CreateByUserId), but aren't set up with triggers of their own to automatically populate these columns. I'm a bit out of my comfort zone as in the past I've only worked with tables that either have these columns populated via database triggers or have transaction tracking done manually but in a separate table (usually something I've seen in dealing with ESBs and ordering systems).
My assumption for why these columns are set up this way is to override fields relating to who the user is, in scenarios where the user is authenticated but the web application connection to the database is done through an application user account.
So my question is in designing Models that map to these tables do I just extend a "DBEntity" type class and call an "Update/Updated" routine prior to doing any modifications? Also, is having these type of manually populated transaction columns common? Thanks.
public class DBEntity
{
//Primary Key
public int Id { get; set; }
public DateTime LastModDate {get; set;}
public int LastModByUserId {get; set;}
public DateTime CreateDate {get; set;}
public int CreateByUserId {get; set;}
public DBEntity(UserLogin currentUser)
{
CreatedDate=DateTime.Now;
CreatedByUserId=currentUser.Id;
Updated (UserLogin);
}
public void Updated (UserLogin user)
{
LastModDate =DateTime.Now;
LastModUserId =user.Id;
}
}
public class UserLogin : DBEntity
{
public string Name { get; set; }
public string UserName { get; set; }
public string UserPassword { get; set; }
}