Iterate output of "mapper.FetchAsync" from Scylla/Cassandra db in c#?

113 views
Skip to first unread message

Check Peck

unread,
May 7, 2020, 9:59:47 AM5/7/20
to DataStax C# Driver for Apache Cassandra User Mailing List
I am playing with Scylla/Cassandra db and working with C# for the first time in 15 years.

After reading about Scylla and C# for few days I got below code. In the below code, I connect to the scylla cluster and try to query a table to get data from it.

    public static async void test()
    {
        var cluster = Cluster.Builder().AddContactPoints("test-endpoint-scylladb").WithQueryOptions(new QueryOptions().SetConsistencyLevel(ConsistencyLevel.LocalQuorum)).Build();
        var session = cluster.Connect("processks");
        var mapper = new Mapper(session);
    
        var cql = Cql.New("SELECT * FROM test LIMIT 10");
        var fetchResult = await mapper.FetchAsync<User>(cql).ConfigureAwait(false);
        // this just prints the object which is not what I want
        Console.WriteLine(fetchResult);
    }

Below is my `User` class:

    using System.Collections.Generic;
    using Cassandra.Mapping;
    using Cassandra.Mapping.Attributes;
    
    namespace Test.Objects.DTO.Scylla
    {
        [TableName("test")]
        [PrimaryKey("client_id")]
        public class User
        {
            [Column("client_id")]
            public int ClientId { get; set; }
    
            [Column("md")]
            public string MD { get; set; }
    
            [Column("process_ids")]
            public List<int> ProcessIds { get; set; }
        }
    }

How can I iterate "fetchResult" object to print out the data I got back after executing the above query?

This is the code link  of Mapper class where "FetchAsync" method is defined.

João Reis

unread,
May 7, 2020, 11:25:19 AM5/7/20
to DataStax C# Driver for Apache Cassandra User Mailing List
Hi,

I've answered this on the stackoverflow question [1].

You might be interested in checking out our examples [2] (you can select C# on the Language dropdown field).

There's also the driver manual section about the Mapper [3].

Thanks,
João Reis

Reply all
Reply to author
Forward
0 new messages