1
我想保存和检索一个对象POCO向和从卡桑德拉使用Datastax C#驱动程序(.Net框架4.6.1,Datastax C#驱动3.0.8)如何使用Datastax C#驱动程序将C#枚举映射到Cassandra字段?
实施例:
public enum DocumentState
{
New = 0,
Approved = 1,
Rejected = 2
}
public class DocumentReadModel
{
public Guid DocumentId { get; set; }
public DocumentState State { get; set; }
}
什么是在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
我应该使用另一种类型,在卡桑德拉int? 以不同的方式配置驱动程序?
hm ...映射是否正确,您是否使用Mapper.Insert()方法?确保在调用映射器方法之前定义映射。我刚刚推出了一个集成测试,其中涵盖了您所描述的类似场景:https://github.com/datastax/csharp-driver/pull/268 – jorgebg
谢谢。我通过公司自己的包装来使用驱动程序,因此存在这个问题。 – user1238350