private SqlExpression BuildSearchExpression(DateTime logTimeFrom, DateTime logTimeTo, string userCode, bool appendWhere = true) {
SqlExpression expression;
expression = SqlExpression.And(
SqlExpression.Column("LogTime", "").GreaterThanOrEqual(SqlExpression.Parametric<DateTime>("@logTimeFrom", logTimeFrom)),
SqlExpression.Column("LogTime", "").LessThanOrEqual(SqlExpression.Parametric<DateTime>("@logTimeTo", logTimeTo))
).Parentheses();
if (!string.IsNullOrEmpty(search.UserCode)) {
expression = expression.And(SqlExpression.Column("UserCode", "").Equal(SqlExpression.Parametric<string>("@userCode", userCode)));
}
return (!appendWhere ? expression : SqlExpression.Where(expression));
}
SqlExpression expression = BuildSearchExpression(search);
expression.ToString();
WHERE (LogTime >= @logTimeFrom AND LogTime <= @logTimeTo) AND UserCode = @userCode
IEnumerable<ISqlParametric> list = expression.GetSqlParametrics();
IEnumerable<DbParameter> parameters = list.Select(x => ( ... ));