简体   繁体   English

如何使用Servicestack.Ormlite将两个SqlExpression With和Condition结合在一起

[英]How to join two SqlExpression With And Condition using Servicestack.Ormlite

I need to filter out some data at generic class, I don't know how to join two SqlExpression<T> with AND condition. 我需要过滤通用类中的一些数据,我不知道如何使用AND条件连接两个SqlExpression<T> I tryed: 我尝试过:

public List<T> Select(SqlExpression<T> expression)
{
    var list = new List<T>();
    using (var db = OpenConnection().Open())
    {
        if (_stores)
        {
            list = db.Select<T>(expression);
        }
        else
        {
            var q = db.From<T>().Where(x => (x as EntityBase).store_id == _store_id);
            list = db.Select<T>(q, expression);
        }
    }
    return list;
}

But this is not working 但这不起作用

list = db.Select<T>(q, expression); // this is not working

SqlExpression<T> OrmLite's typed query builder, there can only be 1 query builder so you can't merge 2 query builders together, you need to apply whatever conditions you want to the existing query builder, eg: SqlExpression<T> OrmLite的类型化查询构建器,只能有1个查询构建器,因此不能将2个查询构建器合并在一起,需要将所需的任何条件应用于现有查询构建器,例如:

public List<T> Select(SqlExpression<T> expression) =>
    db.Select(expression.And(x => (x as EntityBase).store_id == _store_id));

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

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