我有一个实体:
var sf = context.GetSearchFilter(id);
public partial class SearchFilter {
public void DoWork(Type t) {
// When sfc.Process() is called with this SearchFilterCriteria,
// the problem occurs. The method cannot be found.
this.SearchFilterCriterias.Add(new SearchFilterCriteria() { SearchFilter = this }); // other properties added for processing, but irrelevant for this case
foreach(var sfc in this.SearchFilterCriterias) { // SearchFilterCriterias are child entities of SearchFilter
sfc.Process(t);
}
}
}
public partial class SearchFilterCriteria {
public void Process(Type t) {
var mi = this.GetType().GetMethod("Process" + t.Name);
// mi is null when this SearchFilterCriteria is newly added
}
}
对于未作为相关实体从数据库中提取的SearchFilterCriterias,无法找到该方法。 在Process();中,mi为null;
注意:方法存在。
任何人都知道如何解决这个问题?
答案 0 :(得分:0)
原来我只是声明了我的方法。