【发布时间】:2015-09-24 07:54:09
【问题描述】:
抱歉,如果我遗漏了一些明显的东西!但我希望实体框架能够对所有添加/更新操作执行通用方法。
我正在构建一个自定义 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
}
}
我想问题是,我可以集中上述方法来触发所有添加/更新/删除操作吗?
如果这不可能,谁能提出更好的解决方案?
【问题讨论】:
标签: c# entity-framework