获取插入的行cassandra .Net的ID [英] Obtaining ID of inserted row cassandra .Net

查看:49
本文介绍了获取插入的行cassandra .Net的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用datastax C#驱动程序在cassandra数据库中插入一行,我的示例代码如下:

I'm using the datastax C# driver to insert a row into a cassandra database, my sample code looks like this:

var cluster = Cluster.Builder()
  .AddContactPoints("localhost")
  .Build();

using(cluster)
{
    var connection = cluster.Connect();
    connection.ChangeKeyspace("development");
    var simple = connection.Prepare(@"INSERT INTO test(id,customer,content,created_at,line_ids) VALUES (uuid(), 'test customer', ?,'2014-10-24',?);");

    var cmd = simple.Bind("content",new HashSet<Guid>{ Guid.NewGuid() });


    var result = connection.Execute(cmd);
}

如何获取插入的行的ID?

How can I obtain the id of the row that I inserted?

推荐答案

为什么不自己输入ID?将 uuid()替换为一些guid(由 Guid.NewGuid()创建),因为您已经拥有了是最初创建它的人。

Why not pass in the id yourself? Replace uuid() with some guid (created by Guid.NewGuid()) and you'll have it since you were the one who created it in the first place.

这篇关于获取插入的行cassandra .Net的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆