繁体   English   中英

实体框架通用存储库查询

[英]Entity Framework Generic Repository Query

我在下面有此函数,在这里我想将T定义为一个类。 这可能吗。 IsActive和RecordStatusCode在每个模型类中。 有可能以这种方式查询。 谢谢

    public IQueryable<T> GetActive()
    {
        return DbContext.Set<T>().Where(x => x.IsActive && x.RecordStatusCode == "A");
    }

尝试这个:

public IQueryable<T> GetActive()
    {
       var t = typeof(T);  
       var isActiveProperty = t.GetProperty("IsActive");
       var recordStatusCodeProperty=  t.GetProperty("RecordStatusCode");

     return DbContext.Set<T>().Where(x => (bool)isActiveProperty.GetValue(x, null) && recordStatusCodeProperty.GetValue(x, null).ToString() == "A");
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM