我认为Dapper可以合并多个这样的查询

时间:2012-06-19 19:37:40

标签: c# sqlite dapper

我正在使用Dapper micro ORM。我认为它可以处理这样的枚举:

string sql = @"SELECT * FROM Events WHERE TimestampTicks <= @TimestampTicks AND TelemetryId = @TelemetryId ORDER BY TimestampTicks DESC LIMIT 1";
var events = _connection.Query<ReplayEvent>(sql, telemetryIds.Select(ti => new { TimestampTicks = startTime.Ticks, TelemetryId = ti }));

唉,它给出了一个毫无价值的错误。 Query方法没有办法合并多个结果吗?什么是正确的方法?

1 个答案:

答案 0 :(得分:0)

我相信您可以使用子查询并使用Dapper页面上引用的“列表支持”中的内置版本来执行此操作:

string sql = @"SELECT * FROM Events e WHERE TimestampTicks = 
    (SELECT MAX(TimestampTicks) FROM Events WHERE TimestampTicks <=@TimestampTicks AND TelemetryId = e.TelemetryId ) 
    AND e.TelemetryId IN @TelemetryIds;"
var events = _connection.Query<ReplayEvent>(sql, new {TelemtryIds = telemetryIds, TimestampTicks = startTime.Ticks});