0
votes

I set up all of my caches using SQL api; I want to use Linq to query over the data in these tables.

How to do this properly?

This is what I have. My model look like this:

public class Thing
{
    [QuerySqlField]
    public Guid Id { get; set; }

    [QuerySqlField]
    public string Name { get; set; }

    [QuerySqlField]
    public DateTime EffectiveDate { get; set; }
}

I defined the table as follow:

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""

Now I am attempting a linq over that

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

I get the following error because the sql looks like this:

'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]'
It seems to be working fine for me. What's your concern? Try something more complex like cli.GetCache<Guid, Thing>(typeof(Thing).FullName).Where(f => filter(f)).Select(record => record.Value.Field) - Alexandr Shapkin
I updated the question to include the whole scenario. - herme 0