All,
I am working from the following MSDN Article Yet I am getting: "Cannot resolve symbol SavingChanges"
The call in question is:
contextProxy.SavingChanges += new EventHandler(context_SavingChanges);
contextProxy is of type: public class ReportingContext : DbContext which is my context class that handles all EF data models, etc. So if the issue is that DBContext does not inherit from whatever SavingChanges needs (ObjectContext?) how can I fix?
My implementation
public class ReportingProxy
{
// Define the object context to be provided.
private ReportingContext contextProxy = new ReportingContext();
public ReportingProxy()
{
// When the object is initialized, register the
// handler for the SavingChanges event.
contextProxy.SavingChanges += new EventHandler(context_SavingChanges);
}
// Method that provides an object context.
public ReportingContext Context
{
get
{
return contextProxy;
}
}
// SavingChanges event handler.
private void context_SavingChanges(object sender, EventArgs e)
{
var newClubIdToUpdate = 0;
// Ensure that we are passed an ObjectContext
ObjectContext context = sender as ObjectContext;
if (context != null)
{
// Validate the state of each entity in the context before SaveChanges can succeed.
foreach (ObjectStateEntry entry in
context.ObjectStateManager.GetObjectStateEntries(
EntityState.Added | EntityState.Modified | EntityState.Deleted))
{
if (SecurityHelper.IsValidNewClubTableName(entry.EntitySet.Name))
{
if (!entry.IsRelationship && (entry.Entity.GetType() == typeof (NewClub)))
{
var nc = entry.Entity as NewClub;
newClubIdToUpdate = (nc != null ? nc.Id : 0);
}
if (!entry.IsRelationship && (entry.Entity.GetType() == typeof (NewClubProspect)))
{
var ncp = entry.Entity as NewClubProspect;
newClubIdToUpdate = (ncp != null ? ncp.NewClubId : 0);
}
}
}
//Update the NewClub.LastActivityDate column
if (newClubIdToUpdate > 0)
{
string q = @"UPDATE NewClub SET LastActivityDate='" + DateTime.Now + "' WHERE Id=" + newClubIdToUpdate;
using (var cxt = new ReportingContext())
{
var result = cxt.Database.ExecuteSqlCommand(q);
}
}
}
}
}