Is there a non-complex way of auditing Entity Changes for insert/add? I use the code below to record Entity changes for Edit/Update
var context = new DBEntities(connection());
try
{
BPCategory Bp = context.BPCategories.First(e => e.id == id);
Bp.Category = Category;
Bp.PercentShare = Percent;
Bp.BPCategory1 = BPCategory;
Bp.Code = Code;
Bp.Status = Inactive;
var objState = context.ObjectStateManager.GetObjectStateEntry(Bp);
var modProps = objState.GetModifiedProperties();
foreach (var propName in modProps)
{
if (!Equals(objState.OriginalValues[propName], objState.CurrentValues[propName]))
{
//save audit
}
}
context.SaveChanges();
}
catch (Exception ex)
{
throw ex;
}
But i'm struggling when it comes to add/insert. How can i do this for insert/add?
var context = new DBEntities(connection());
BPCategory Bp = new BPCategory
{
Category = Category,
PercentShare = PercentShare,
BPCategory1 = BPCategory,
Code = Code,
Status = Inactive
};
context.BPCategories.AddObject(Bp);
context.SaveChanges();