question

siva_176577 avatar image
siva_176577 asked Erick Ramirez edited

Handling C# Nested Classes

Hi all

I have a C# class as like below

public class User
{
    public string UserId { get; set; }
    public string Name { get; set; }
    public List<address> Address { get; set; }
}

public class Address
{
    public string Line1 { get; set; }
}

I created key space and table as below

ISession session;
IMapper Mapper;
Table table;

var mapping = MappingConfiguration.Global.Define(
new Map()
    .TableName(typeof(User).Name)
    .PartitionKey(u => u.UserId));

Dictionary<string, string> replication = new Dictionary<string, string>();
replication.Add("class", "SimpleStrategy");
replication.Add("replication_factor", "3");

var cluster = Cluster.Builder()
    .AddContactPoints("127.0.1")
    .WithPort(9042)
    .WithLoadBalancingPolicy(new DCAwareRoundRobinPolicy("test"))
    .WithReconnectionPolicy(new FixedReconnectionPolicy(400, 5000, 2 * 60000, 60 * 60000))
    .Build();

session = cluster.Connect();
session.CreateKeyspaceIfNotExists("demo1", replication);
session = cluster.Connect("demo1");

table = new Table<User>(session, mapping, typeof(User).Name, "demo1");
table.CreateIfNotExists();

I am getting the following error

Cassandra.InvalidTypeException: 'Unknown Cassandra target type for CLR type Casandra.Address'
csharp driverlinq
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

jorgebg avatar image
jorgebg answered

Hi @siva_176577,

thanks for creating the post on DataStax Community site, I've replied on stackoverflow.com: https://stackoverflow.com/questions/57519742/handling-c-sharp-nested-classes-in-cassandra/57552958#57552958


Thanks,

Jorge

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.