1

我正在使用 Dapper 微型 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 方法没有合并多个结果的方法吗?这样做的正确方法是什么?

4

1 回答 1

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});
于 2012-06-26T18:18:52.233 回答