C#C
C#9mo ago
VoidPointer

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.
var pkeys= qry.GetTableColumns(tableName)
    .Where(col => col.Kind == Column.ColumnKinds.PartitionKey)
    .Select(col => new PropertyGenerationModel(col));
var ckeys= qry.GetTableColumns(tableName)
    .Where(col => col.Kind == Column.ColumnKinds.Clustering)
    .Select(col => new PropertyGenerationModel(col));

In case it helps, GetTableColumns is querying a Cassandra db like this:
using Cassandra.Mapping;
using CassandraClient.Config;
using CassandraClient.Metadata.Models;
namespace CassandraClient.Metadata;

public class MetaDataQueries(SessionOptions options)
{
    public IEnumerable<Column> GetTableColumns(string tableName)
    {
        var session = SessionFactory.GetSession(options);
        Mapper mapper = new(session);
        var columns = mapper.Fetch<Column>(
            $"select * from system_schema.columns where table_name = '{tableName}' and keyspace_name = '{session.Keyspace}' allow filtering;");
        return columns;
    }
}
Was this page helpful?