类型.GetMethod对新实例化的实体linq-to-sql不返回任何值

本文关键字:linq-to-sql 返回 任何值 实体 GetMethod 实例化 类型 | 更新日期: 2023-09-27 18:17:02

我有一个实体:

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
    }
}

对于没有作为相关实体从数据库中提取的searchfiltercriteria,无法找到该方法。

注意:方法存在

有人知道如何解决这个问题吗?

类型.GetMethod对新实例化的实体linq-to-sql不返回任何值

原来我的方法声明不正确。