I'm looking for the correct way to use the official Cassandra C# driver (2.0) in a ASP.NET Web API project - used by a high traffic site.
I've made a very simple sample app that connects to a cassandra db using the following classes:
public class CassandraContext
{
private static ISession _session;
public ISession Session { get { return _session; } }
public CassandraContext()
{
var cluster = Cluster.Builder().AddContactPoint("cassandra.some.server").Build();
_session = cluster.Connect("keyspace");
}
}
And in my Controller I'm using it like this:
public class TestController : ApiController
{
static CassandraContext db = new CassandraContext();
public IHttpActionResult Get()
{
var result = new List<string>();
var rowSet = db.Session.Execute(@"SELECT * FROM ""Test"";");
foreach (var row in rowSet)
result.Add(row.GetValue<string>("data"));
return Ok<List<string>>(result);
}
}
Any examples, information will be very helpful.
Thanks.