【发布时间】:2021-11-21 19:17:42
【问题描述】:
我使用 SQL api 设置了所有缓存;我想使用 Linq 来查询这些表中的数据。
如何正确地做到这一点?
这就是我所拥有的。我的模型如下所示:
public class Thing
{
[QuerySqlField]
public Guid Id { get; set; }
[QuerySqlField]
public string Name { get; set; }
[QuerySqlField]
public DateTime EffectiveDate { get; set; }
}
我将表格定义如下:
CREATE TABLE IF NOT EXISTS Things (
Id UUID,
Name VARCHAR,
EffectiveDate TIMESTAMP,
PRIMARY KEY(Id))
WITH ""
TEMPLATE = PARTITIONED,
CACHE_NAME = consoleappserver.Thing,
VALUE_TYPE = consoleappserver.Thing""
现在我正在尝试对此进行 linq
var cache = cli.GetCache<Guid, Thing>(typeof(Thing).FullName);
var things = cache.AsCacheQueryable();
var effectiveDate = DateTime.SpecifyKind(DateTime.Today, DateTimeKind.Utc);
things = things.Where(t => t.Value.EffectiveDate <= effectiveDate);
foreach (var kv in things)
{
Console.WriteLine("Things #{0} '{1}'",
kv.Value.Id, kv.Value.Name);
}
我收到以下错误,因为 sql 看起来像这样:
'Failed to parse query. Column "_T0.EffectiveDate" not found; SQL statement:
select _T0._KEY, _T0._VAL from "PUBLIC"."THINGS" as _T0
where (_T0."EffectiveDate" <= ?) [42122-199]'
【问题讨论】:
-
对我来说似乎工作正常。你有什么顾虑?尝试更复杂的方法,例如 cli.GetCache
(typeof(Thing).FullName).Where(f => filter(f)).Select(record => record.Value.Field) -
我更新了问题以包含整个场景。
标签: c# sql linq .net-core ignite