Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

vilco.letavay_159813 avatar image
vilco.letavay_159813 asked ·

Per-query keyspace using csharp-driver

Hi, we're using csharp-driver in our application and we would like to execute queries (using Table<TEntity>) at various keyspaces. SimpleStatement.SetKeyspace() doesn't have any effect on the actual query's keyspace (documentation states that this method is only to provide a hint for token-aware routing).

Therefore it seems like our only option is to either use ISession.ChangeKeyspace() before every query to set a session wide keyspace or to use a separate session for each keyspace. Isn't there a better approach to achieve the desired functionality?

Thanks!

csharp-driverkeyspace
10 |1000 characters needed characters left characters exceeded

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

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

@vilco.letavay_159813 an ISession can only be set to one keyspace at a time so you will need to create a session instance for each keyspace.

As a side note, think of a Cassandra keyspace as a database instance -- in most implementations, it should contain all the tables that is used by each application. Although this isn't a strict rule, this is how most users model their data so a single session instance is sufficient. If you don't really need the complexity of splitting your tables across multiple keyspaces, consider modelling your data to just one keyspace. Cheers!

Share
10 |1000 characters needed characters left characters exceeded

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