Building potentially long LINQ queries in fluentcassandra

283 Views Asked by At

I have a columnfamily that I've generated programmatically (along with secondary indexes), and now want to query it at run time with an arbitrary number of parameters. I've done this by running the following code:

var queryParams = new Dictionary<string, string>();

//populate queryParams
.
.
.

IQueryable<ICqlRow> query = family;
queryParams.Keys.ToList().ForEach(paramKey => query = query.Where(q => q[paramKey] == queryParams[paramKey]));

I'm having two problems with this. The first is I get a "Call is not supported" exception when I try to evaluate the query. I came across another issue as I begin to break it down to smaller examples.

I tried something simple:

query = query.Where(t => t["Param1"] == "Value1");

That worked fine. The CQL it generated was

SELECT * 
FROM SampleColumnFamily 
WHERE Param1 = 'Value1'

I tried beefing up my simple example:

query = query.Where(t => t["Param1"] == "Value1").Where(t => t["Param2"] == "Value2");

This produced

SELECT * 
FROM  SampleColumnFamily   
WHERE (Param1 = 'Value1' AND Param2 = 'Value2')

It looks good, however this is where I ran into my second issue. I get this error: "line 3:6 no viable alternative at input '('". It turns out it didn't like the () around the where clause. If I remove them, it seems to work fine. Perhaps this is an issue with the LINQ provider in FluentCassandra?

However, that didn't answer my "Call is not supported" exception. After I did some more digging I came up with another scenario.

//This works
query.Where(t => t["Param1"] == "Value1");

//This doesn't
string p1 = "Param1";
query.Where(t => t[p1] == "Value1");

Instead of seeing the CQL when I mouse over query in the IDE, all I see is {FluentCassandra.Linq.CqlQuery}. If I try to execute that query, I get the "Call is not supported" exception.

Any ideas (other than hand writing my CQL)?

0

There are 0 best solutions below