I was wonder what would be the best way to log changes made to objects created by linq.
I have searched around and this is what i came up with:
using (testDBD开发者_C百科ataContext db = new testDBDataContext())
{
Sometable table = db.Sometables.Single(x => x.id == 1);
table.Something = txtTextboxToChangeValue.Text;
Sometable tableBeforeChanges = db.Sometables.GetOriginalEntityState(table);
foreach (System.Data.Linq.ModifiedMemberInfo item in db.Sometables.GetModifiedMembers(table))
{
// Obviously writing to debug is not what i would like to do
System.Diagnostics.Debug.WriteLine("Old value: " + item.OriginalValue.ToString());
System.Diagnostics.Debug.WriteLine("New value: " + item.CurrentValue.ToString());
}
}
Is this really the way to go to log changes?
Change Tracking or Change Data Capture are the way to go. LINQ has nothing to do with it. As a general rule, client side cannot properly track changes that occur in the server because the changes may occur in alternate access that is not occurring through the client. As a cautionary note, setting up a complete data audit for all changes is seldom successful as the performance tax penalty is usually too high.
Ive searched around and i think im gonna use DoodleAudit (doddleaudit.codeplex.com) it seems to give me what i wanted, tnx for helping anyways!
精彩评论