You could make the property set methods protected/private and do a similar thing MVC uses with html helpers.
So you would end up with something like:
someEntity.Update( x => x.Property, propertyValue, user);
If you are confused I can post the Update method declaration.
I am not sure about whether this scenario is common but I certainly think it would be a better idea to implement that as database triggers. But if you must do it manually I think this is the best you can do to automate the process.
EDIT:
Here you go
public class DBEntity
{
public short Prop1 { get; protected set; }
public string Prop2 { get; protected set; }
public DBEntity()
{
}
public void Update<T>( Expression<Func<DBEntity, T>> outExpr, T value)
{
if (value != null)
{
var expr = (MemberExpression)outExpr.Body;
var prop = (PropertyInfo)expr.Member;
prop.SetValue(this, value, null);
}
}
}
Test:
static void Main(string[] args)
{
DBEntity e = new DBEntity();
e.Update<string>(x => x.Prop2, "test");
Console.WriteLine(e.Prop2);
}
Leave me a comment if you still have any questions. Good luck!