I was wondering if there is a better way to update an entity property from inside of an overridden SaveChanges() method. I am currently using straight SQL.
Here is the snippet from SaveChanges()
public override SaveChanges(){
[...]
if (updateId > 0)
{
string q = @"UPDATE NewClub SET
LastActivityDate='" + DateTime.Now + "' WHERE Id=" + updateId;
using (var context = new ReportingContext())
{
//ToDo: exception handling
var result = context.Database.ExecuteSqlCommand(q);
}
}
try
{
saveSuccess = base.SaveChanges() > 0;
}
catch (Exception e)
{
string ex = e.ToString();
}
return saveSuccess ? 1 : 0;
}