道歉,如果我失去了一些明显的东西!但我希望实体框架能够在所有添加/更新操作上执行泛型方法。每个实体框架的消防方法添加/更新/删除操作
我正在构建一个自定义SaveHistory
功能,它将T
作为一个参数,它基本上就是正在处理的实体框架对象。
核心方法:
//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
}
}
我想的问题是,我可以集中上述方法用来触发所有添加/更新/删除操作?
如果这是不可能的,任何人都可以提出更好的解决方案吗?
似乎似乎......是否有可能接收正在处理的对象?由于SaveChanges通常“提交”而不是“交互” –
@TezWingfield是的,你可以使用ChangeTracker属性 –