I have been trying to insert data into cassandra keyspace using datastax cassandra c# driver using batch .Trying to insert 100 rows in a batch.Code is working fine but when i check the column family there is no data. Please suggest why data insertion is not working if anyone knows? If there is any exception why catch is unable to get that exception ? There is no issue while inserting data through cqlsh command line.
private static void InsertData(ISession session, List<cf_Data> lsData)
{
try
{
var table = session.GetTable<cf_Data>();
table.CreateIfNotExists();
int count = 0;
var batch =session.CreateBatch();;
foreach (cf_Data val in lsData)
{
try
{
if (((count) % 100) == 1)
{
batch = session.CreateBatch();
}
batch.Append(table.Insert(val));
if (count % 100 == 0)
{
batch.Execute();
}
}
catch (Exception)
{
throw;
}
count++;
}
}
catch (Exception)
{
throw;
}
}
For mapping C# class to Cassandra Column Family, Cassandra.Mapper namespace is used. Mapper class code :
[AllowFiltering]
[Table("cf_Data ")]
internal class cf_Data
{
[PartitionKey]
public Guid Id { get; set; }
public DateTimeOffset Rundate { get; set; }
public DateTimeOffset OtherDate{ get; set; }
public String StudentFirstName { get; set; }
public String StudentLastName { get; set; }
}
cf_Data
table? Check this by runningselect count(*) from cf_Data
incqlsh
. How do you generate id:Guid Id
? – oleksii