【发布时间】:2017-03-24 09:08:18
【问题描述】:
我想使用 Datastax C# 驱动程序(.Net Framework 4.6.1、Datastax C# 驱动程序 3.0.8)在 Cassandra 中保存和检索 POCO 对象
例子:
public enum DocumentState
{
New = 0,
Approved = 1,
Rejected = 2
}
public class DocumentReadModel
{
public Guid DocumentId { get; set; }
public DocumentState State { get; set; }
}
在 Cassandra 中持久保存该对象的最佳方法是什么?
我的方法似乎不起作用。
现在我尝试在 Cassandra 中将其保存为 int:
create table if not exists documentreadmodel (
documentid uuid PRIMARY KEY,
state int);
还使用了 Datastax 驱动程序提供的映射配置,代码如下:
MappingConfiguration.Global.Define(
new Map<DocumentReadModel>()
.TableName("documentreadmodel")
.PartitionKey(o => o.MerchantId)
.Column(o => o.State, c => c.WithName("state").WithDbType<int>()));
但我仍然遇到异常:
Cassandra.InvalidTypeException:
Unknown Cassandra target type for CLR type ValueObjects.DocumentState
我应该在 Cassandra 中使用另一种 int 类型吗? 以不同方式配置驱动程序?
【问题讨论】:
-
hm...映射正确,你用的是
Mapper.Insert()方法吗?确保在调用映射器方法之前定义了映射。我刚刚向 repo 推送了一个集成测试,涵盖了您描述的类似场景:github.com/datastax/csharp-driver/pull/268 -
谢谢。我通过我公司自己的包装器使用驱动程序,因此出现了问题。
标签: c# enums cassandra datastax