sikor1994
sikor1994

Reputation: 11

Cassandra C# driver UDT Mapping - Int to Enum

I've got the enum type:

public enum SomeType
{
    Type1,
    Type2,
    Type3
}

and I'd like to map automatically Cassandra int type to the c# enum. I've tried to define it like:

session.UserDefinedTypes.Define(
            UdtMap.For<DefinedType>()
            .Map(a => a.Type, "type"));
// where type of a.Type is SomeType

however it throws the "InvalidTypeException" with message " type type Int32 is not assignable to SomeType"

Is it possible to map it automatically ? I've seen some examples of table column mapping to enumerable, but never any of UDT

Upvotes: 1

Views: 741

Answers (1)

Sea cucumber
Sea cucumber

Reputation: 71

Cassandra not yet supported enum type in udt,

Alternatively, you can solve the problem as follows

public enum SomeType
{
Type1=0,
Type2=1,
Type3=2
}

public SomeType SomeTypeProperty;

public int SomeTypePropertyMapForCassandra
{
 get
 {
 return SomeTypePropertyMapForCassandra;
 }
 set
 {
 this.SomeTypeProperty= (SomeType)value;
 }
}

Upvotes: 1

Related Questions