Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.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
C# Cassandra/C-在映射上插入空值_C#_Cassandra_Datastax - Fatal编程技术网

C# Cassandra/C-在映射上插入空值

C# Cassandra/C-在映射上插入空值,c#,cassandra,datastax,C#,Cassandra,Datastax,当我尝试插入/更新带有空IEnumerable的POCO时,我在使用带有Mapper扩展的DataStax c驱动程序时遇到了一些问题,其中IEnumerable是一个映射或一个冻结列表 驱动程序不应该自动生成墓碑吗?我在Insert上添加了insertNulls:true选项,但仍有例外: Exception caught: 'System.ArgumentNullException' in Cassandra.dll ("Null values are not supported insid

当我尝试插入/更新带有空IEnumerable的POCO时,我在使用带有Mapper扩展的DataStax c驱动程序时遇到了一些问题,其中IEnumerable是一个映射或一个冻结列表

驱动程序不应该自动生成墓碑吗?我在Insert上添加了insertNulls:true选项,但仍有例外:

Exception caught: 'System.ArgumentNullException' in Cassandra.dll ("Null values are not supported inside collections")  136.11s     [1732]  
下面是我恢复实体属性的部分代码,以使其更易于理解。所有内容都映射到表和udt:

卡桑德拉模式:

CREATE TYPE IF NOT EXISTS maintenancetime (
    id uuid,
    beg int,
    end int
);

CREATE TABLE IF NOT EXISTS bank (
    id uuid PRIMARY KEY,
    name text,
    maintenancetime set<frozen<maintenancetime>>
);
C代码:

public class Bank {
    public Guid Id {get; set;}
    public string Name {get; set;}
    public IEnumerable<MaintenanceTime> MaintenanceTime { get; set; }
}

public class MaintenanceTime {
    public Guid Id { get; set; }
    public int Beg { get; set; }
    public int End { get; set; }
}

Bank entity = new Bank();
bank.Id = Guid.NewGuid();
bank.MaintenanceTime = null;
bank.Name = "Test";

CassandraConnection.Mapper.Insert<Bank>(entity, true);

在Cassandra中,您可以插入映射列并将其设置为null以生成墓碑,但不支持将单元格值设置为包含键的null值的映射

例如,在以下查询中,不允许包含空值的映射:

INSERT INTO tbl (id, map_col) VALUES (?, ?)
UPDATE tbl SET map_col = ? WHERE id = ?
这就是为什么司机要阻止它

当列未冻结时,可以使用下面的查询将给定键的特定映射值设置为null,如

不支持将特定映射值设置为null

支持使用更新

cqlsh:music> create table mm(id bigint PRIMARY KEY, m map<int, text>);
cqlsh:music> INSERT INTO mm(id,m) VALUES(1, {1: 'one', 2: 'two'});
cqlsh:music> UPDATE mm SET m[1]=null WHERE id=1;
cqlsh:music> SELECT * FROM mm;

 id | m
----+------------
  1 | {2: 'two'}

我使用的是Cassandra 3.4

没错,我更新了我的答案以包含这个示例。正如我所说的,问题在于C驱动程序的映射器扩展。cqlsh工作正常。您好Jorge,正如我在OP上提到的,我无法使用映射器扩展插件进行插入。但是,我可以用cqlsh进行插入/更新。你能发布你的代码吗?
cqlsh:music> create table mm(id bigint PRIMARY KEY, m map<int, text>);
cqlsh:music> INSERT INTO mm(id,m) VALUES(1, {1: 'one', 2: 'two'});
cqlsh:music> UPDATE mm SET m[1]=null WHERE id=1;
cqlsh:music> SELECT * FROM mm;

 id | m
----+------------
  1 | {2: 'two'}