我認為Dapper可以合併這樣的多個查詢

c# dapper sqlite

我正在使用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方法沒有辦法合併多個結果嗎?這樣做的正確方法是什麼?

一般承認的答案

我相信您可以使用子查詢並使用Dapper頁面上引用的“List Support”中的構建來執行此操作:

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});


許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因