Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
迭代;任务<;IEnumerable<;T>&燃气轮机&引用;在c#中?_C#_Cassandra_Scylla - Fatal编程技术网

迭代;任务<;IEnumerable<;T>&燃气轮机&引用;在c#中?

迭代;任务<;IEnumerable<;T>&燃气轮机&引用;在c#中?,c#,cassandra,scylla,C#,Cassandra,Scylla,我15年来第一次与“锡拉db”一起玩,与“C#”一起工作 在读了几天关于“锡拉”和“C#”的书后,我得到了下面的代码。在下面的代码中,我连接到scylla集群并尝试查询一个表以从中获取数据 public static async void test() { var cluster = Cluster.Builder().AddContactPoints("test-endpoint").WithQueryOptions(new QueryOptions().SetConsistencyL

我15年来第一次与“锡拉db”一起玩,与“C#”一起工作

在读了几天关于“锡拉”和“C#”的书后,我得到了下面的代码。在下面的代码中,我连接到scylla集群并尝试查询一个表以从中获取数据

public static async void test()
{
    var cluster = Cluster.Builder().AddContactPoints("test-endpoint").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);
}
如何迭代
fetchResult
对象以打印出执行上述查询后返回的数据

这是定义了
FetchAsync
方法的
Mapper
类的代码,它返回
Task
对象

var fetchResult = await mapper.FetchAsync<User>(cql).ConfigureAwait(false);
或者,您可以使用JSON库将用户对象转换为JSON字符串,而不是重写
ToString()

[编辑]您可能对我们的示例和文档感兴趣:

(您可以按C语言进行筛选)

var fetchResult = await mapper.FetchAsync<User>(cql).ConfigureAwait(false);
Console.WriteLine(string.Join(Environment.NewLine, fetchResult));
Console.WriteLine(string.Join(
    Environment.NewLine, 
    fetchResult.Select(user => JsonConvert.SerializeObject(user))))