One IEnumerable with 1 item mysteriously becomes empty after I query a second IEnumerable
The variable
pkeys
has one item immediately after the query that returns it is executed, but then when the query that returns ckeys
query is executed, suddenly pkeys
shows Enumeration yielded no results while ckeys
contains one item.
In case it helps, GetTableColumns
is querying a Cassandra db like this:
5 Replies
so you are saying
pkeys
is not materialized?
what's the lifetime of SessionFactory.GetSession
?I would have said the session's lifetime is only for the duration of the
GetTableColumns
method, but now on closer inspection I see ISession
is an IDiposable
, and I don't have a using
for it. Just maybe that has something to do with it.
I just ended up slapping ToList()
on the end of the queries and everything works nicely now.As an aside, It looks like you're opening yourself up for cql injection by using string interpolation here.
Is there a way to parmeterize this query?
The code I posted here was just proof of concept, getting to know the DataStax
Mapper
for Cassandra, and I had just copied from some legacy code without checking anything. That code not using parameters, I didn't think of them yet. I have now parameterized all the queries after seeing that the Mapper
methods nearly all have an overload with a params object[] args
parameter. These args are used to fill in ?
placeholders in the query string.Ah, I see. That's good then :)