gpt4 book ai didi

c# - 我如何使用 servicestack ormlite JoinSqlBuilder

转载 作者:行者123 更新时间:2023-11-30 15:31:28 30 4
gpt4 key购买 nike

没有关于此类的示例或文档。如果我错了,我会很高兴任何链接!

我不明白我应该将什么作为下一个参数传递以及如何使整个事情作为对 SqlConnection 的查询执行。

有人可以帮帮我吗?

 var sql = new JoinSqlBuilder<Schoolyear, Period>()
.Join<Schoolyear, Period>(s => s.Id, p => p.SchoolyearId);
.Where(p => p.MyDate > DateTime.Now) // This Where clause does not work

// How to execute the sql?

// How to attach the query to an SqlConnection?

更新

2 小时后确定:

using (IDbConnection con = dbFactory.OpenDbConnection())
{
var sql = new JoinSqlBuilder<Schoolyear, Period>().Join<Schoolyear, Period>(s => s.Id, p => p.SchoolyearId,
destinationWhere: p => p.LessonDate >= startDateOfWeek && p.LessonDate < endDateOfWeek).ToSql();

return con.Query(sql); /* There is not Query on the idbconnection although ormlite is using the con.Query in its samples? or return dbConn.Exec(dbCmd => dbCmd.Select<T>()); There is no .Select extension method? */

}

最佳答案

您可以找到一些很好的 JoinBuilder 示例 in the unit tests here .要运行连接查询,您需要将构建器转换为 SQL,然后将其传递给 Select,如下所示:

var sql = jn.ToSql();
var items = con.Select<SchoolYearPeriod>(sql);

您还可以将连接构建器与表达式访问者结合使用,这样您就可以在连接后创建复杂的 WHERE 过滤器,如下所示:

SqlExpressionVisitor<SchoolYearPeriod> ev = Db.CreateExpression<SchoolYearPeriod>();
ev.SelectExpression = join.ToSql();
ev.Where(syp => syp.MyDate > DateTime.Now);

关于c# - 我如何使用 servicestack ormlite JoinSqlBuilder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20630997/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com