There are no samples or docu about this class. If I am wrong I would really be pleased about any link!
I do not understand what I should pass as next parameter and how to make the whole thing execute as query on an SqlConnection.
Someone can help me please?
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?
UPDATE
OK 2 hours later:
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? */
}
You can find some good examples of JoinBuilder in the unit tests here . To run the join query you need to convert the builder to SQL and then pass it to Select, like this:
var sql = jn.ToSql();
var items = con.Select<SchoolYearPeriod>(sql);
You can also use the join builder in conjunction with the expression visitor, so you can create complex WHERE filters after the join, like this:
SqlExpressionVisitor<SchoolYearPeriod> ev = Db.CreateExpression<SchoolYearPeriod>();
ev.SelectExpression = join.ToSql();
ev.Where(syp => syp.MyDate > DateTime.Now);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.