2016-11-10 6 views
1

私は(.NET Frameworkの4.6.1、Datastax C#のドライバ3.0.8)Datastax C#のドライバを使用してカサンドラにしてからPOCOオブジェクトを保存および取得したいDatastax C#Driverを使用してC#enumをCassandraフィールドにマップする方法はありますか?

例:

public enum DocumentState 
{ 
    New = 0, 
    Approved = 1, 
    Rejected = 2 
} 

public class DocumentReadModel 
{ 
    public Guid DocumentId { get; set; } 
    public DocumentState State { get; set; } 
} 

何カッサンドラでこのオブジェクトを永続させる最善の方法は?

私のアプローチはうまくいかないようです。

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>())); 

をしかし、私はまだ取得し、今私はカサンドラのintとしてそれを保存しようとしたために

例外:

Cassandra.InvalidTypeException: 
Unknown Cassandra target type for CLR type ValueObjects.DocumentState 

私はカッサンドラのint型を使用しますか? ドライバを別の方法で設定しますか?

+0

hm ...マッピングが正しく、 'Mapper.Insert()'メソッドを使用していますか?マッパーメソッドを呼び出す前にマッピングを定義していることを確認してください。私はちょうどあなたが記述した同様のシナリオをカバーするレポに統合テストをプッシュしました:https://github.com/datastax/csharp-driver/pull/268 – jorgebg

+1

ありがとう。私は私の会社のラッパー、したがって問題を介してドライバを使用していた。 – user1238350

答えて

0

私は、.NET 4.5.2 CassandraCSharpDriverに3.3.2

を使用しています

のために使用するグローバル設定を更新することにより、溶液が

MappingConfiguration.Global.Define(
For<DocumentReadModel>() 
     .TableName("documentreadmodel") 
     .PartitionKey(o => o.MerchantId) 
     .Column(o => o.State, c => c.WithName("state").WithDbType<int>())); 
「は」使用するように設定を更新してみました
関連する問題