我正在使用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方法没有办法合并多个结果吗?什么是正确的方法?
答案 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});