Apologies if I'm missing something obvious! But I'm hoping that Entity Framework has the ability to execute a generic method on all Add/Update actions.
I'm building a custom SaveHistory
feature that takes T
as a param which essentially would be the Entity Framework object that's being worked on.
Core method:
//TODO - Requires additional logic
public void SaveHistory<T>(T type, [CallerFilePath]string callerFilePath = "")
{
//Caller File Path just returns the location of where the method was executed
//This enables us to retrieve the module location
//Get the Name of the class(Type that's been passed in)
var className = typeof(T).Name;
//Get a collection of module names
var enumNames = Enum.GetNames(typeof (Department));
//Does any of the module names equal the executing assembly
if (enumNames.Any(callerFilePath.Contains))
{
//Now I can search the string to see if an action came from a module
}
else
{
//If not it could be an error or calling from a core object
//Needs work
}
}
I suppose the questions is, can I centralize the method above to fire on all Add/Update/Remove actions?
If this is not possible, could anyone suggest a better solution?