如何执行一般的Where Lambda子句。?
我有许多实体需要相同的Where查询。
public Func<SupplierTypeText, bool> GetLmbLang()
{
return (p => p.LangID == 1);
}
public Func<ProductText, bool> GetLmbLang()
{
return (p => p.LangID == 1);
}
public Func<CategoryText, bool> GetLmbLang()
{
return (p => p.LangID == 1);
}
我想要一个通用方法,比如
//public interface IRepository<T> : IRepository<T> where T : class
public Func<T, bool> GenericGetLmbLang()
{
return (p => p.LangID == 1);
}
如果我可以直接在Where子句中调用GetLmbLang(),这将非常有用。
var ViewModel = _db.Suppliers.Select(model => new
{
model,
SupType = _db.SupplierTypeTexts.Where(a => GenericGetLmbLang())
});
------更新--------
这就是我所做的一切,没有任何效果。
public class BaseGenericModel
{
public int LangID { get; set; }
public Func<BaseGenericModel, bool> GetLmbLang()
{
return (p => p.LangID == 1);
}
}
我的界面是
public interface IBaseRepository<T> where T : BaseGenericModel
{
Func<T, bool> GetLmbLang();
}
public class BaseRepository<T> : IBaseRepository<T> where T : BaseGenericModel
{
public Func<T, bool> GetLmbLang()
{
return (p => p.LangID == 1);
}
}
我无法从我的供应商类型文本、产品文本、类别文本中调用此存储库。那不管用。