【问题标题】:ClusterKey Attribute in DataStax C# DriverDataStax C# 驱动程序中的 ClusterKey 属性
【发布时间】:2017-01-31 05:20:46
【问题描述】:

我一直在尝试使用 Cassandra 的 Datastax C# 驱动程序中的属性来进行测试对象映射。 在 cassandra 中有一个由

定义的表
CREATE TABLE test.omfieldtest (
    integer int,
    bigint varint,
    stringtext text, 
    universal uuid, 
    bool boolean, 
    singleprecision float,
    variableprecision decimal,
    PRIMARY KEY ((integer), bigint, stringtext, universal)
);

然后我有一个修饰的 C# 类来映射到该表

[Table("test.omfieldtest")]
    public class MappingTest
    {
        [PartitionKey]
        public Int32 integer;
        [ClusteringKey(0, SortOrder.Ascending, Name = "bigint")]
        public Int64 bigint;
        [ClusteringKey(1, SortOrder.Ascending, Name = "stringtext")]
        public string stringVal;
        [ClusteringKey(2, SortOrder.Ascending, Name = "universal")]
        public Guid universal;
        [Column("bool")]
        public bool boolVal;
        [Column("singleprecision")]
        public Single singlePrecisionVal;
        [Column("variableprecision")]
        public decimal variablePrecisionVal;
    }

使用mapper.Insert<MappingTest> 时,会引发 InvalidQueryException,并引发“未知标识符字符串值”问题。如果我更改属性名称以匹配列名称,则一切正常,无论名称属性是什么ClusterKey 设置为。

那么,为ClusterKey 属性指定Name 属性的目的甚至是作用是什么?

【问题讨论】:

  • 您是在使用Cassandra.Mapping.Attributes 命名空间下的属性还是已弃用的Linq 属性?
  • 它们来自Cassandra.Mapping.Attributes 命名空间。

标签: c# cassandra datastax


【解决方案1】:

您似乎遇到了 Mapper/Linq 组件中的驱动程序错误。我创建了一张票来跟踪它:CSHARP-507

幸运的是,有一个解决方法:包括 ColumnAttribute 以及集群键,在您的情况下是:

[Column("stringtext")]
[ClusteringKey]
public string stringVal;

我还在存储库中包含了一个失败的测试:https://github.com/datastax/csharp-driver/commit/9917bfff4ef569525a6df845f35d31d817e79dc0

【讨论】:

    猜你喜欢
    • 2019-12-27
    • 2014-03-27
    • 2017-08-04
    • 2021-01-24
    • 2016-02-27
    • 2017-01-20
    • 2017-01-26
    • 2022-12-11
    • 2014-02-20
    相关资源
    最近更新 更多