Thomas Atwood created CASSANDRA-7996:
----------------------------------------
Summary: Cassandra C# driver errors on virtual properties when
using CreateIfNotExists method
Key: CASSANDRA-7996
URL: https://issues.apache.org/jira/browse/CASSANDRA-7996
Project: Cassandra
Issue Type: Improvement
Components: Drivers (now out of tree)
Reporter: Thomas Atwood
Fix For: 2.1.0
When using the Cassandra C# driver, I receive the error "An unhandled exception
of type 'Cassandra.SyntxError' occurred in Cassandra.dll when attempting to
create a table with an overridden property using the Linq functionality with
the driver. If the property is not overriden, the driver creates the table
without any issues.
Example: concrete object inherits from abstract object where the Id field is
virtual on the abstract object. Reason to override this field would be to
apply certain regex validation for format depending on the derived concrete
object (Id will still be unique across all objects that inherit from the
abstract object).
Abstract object:
using System;
using System.ComponentModel;
using Cassandra.Data.Linq;
namespace TestDatastaxCsDriver.Abstract
{
[AllowFiltering]
[Serializable]
public class AbstractEntity: INotifyPropertyChanged
{
private string _id;
private string _name;
private string _insertuser;
private DateTime _insertimestamp;
private DateTime _modifiedtimestamp;
public event PropertyChangedEventHandler PropertyChanged;
public AbstractEntity(string id, string name, string insertuser)
{
Id = _id;
Name = _name;
InsertUser = _insertuser;
InsertTimestamp = DateTime.Now;
ModifiedTimestamp = DateTime.Now;
}
[PartitionKey]
[Column("id")]
public virtual string Id
{
get { return _id; }
set
{
if (value != _id)
{
_id = value;
NotifyPropertyChanged("Id");
}
}
}
[Column("name")]
public string Name
{
get { return _name; }
set
{
if (value != _name)
{
_name = value;
NotifyPropertyChanged("Name");
}
}
}
[Column("insertuser")]
public string InsertUser
{
get { return _insertuser; }
set
{
if (value != _insertuser)
{
_insertuser = value;
NotifyPropertyChanged("InsertUser");
}
}
}
[Column("inserttimestamp")]
public DateTime InsertTimestamp
{
get { return _insertimestamp; }
set
{
if (value != _insertimestamp)
{
_insertimestamp = value;
NotifyPropertyChanged("InsertTimestamp");
}
}
}
[Column("modifiedtimestamp")]
public DateTime ModifiedTimestamp
{
get { return _modifiedtimestamp; }
set
{
if (value != _modifiedtimestamp)
{
_modifiedtimestamp = value;
NotifyPropertyChanged("ModifiedTimestamp");
}
}
}
private void NotifyPropertyChanged(String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new
PropertyChangedEventArgs(propertyName));
ModifiedTimestamp = DateTime.Now;
}
}
}
}
Concrete object:
using System.ComponentModel.DataAnnotations;
using Cassandra.Data.Linq;
using TestDatastaxCsDriver.Abstract;
namespace TestDatastaxCsDriver.Concrete
{
[Table("issuer")]
public class Issuer : AbstractEntity
{
public Issuer(string id, string name, string insertuser) : base(id,
name, insertuser)
{
}
//Cassandra C# driver chokes on this. No issues if the property is not
overriden. Please note I also tried adding a column attribute to see if it
fixed the problem and it did not.
[MaxLength(3,ErrorMessage = "Id cannot be longer than 3 characters.")]
public override string Id
{
get
{
return base.Id;
}
set
{
base.Id = value;
}
}
}
}
Program.cs to test:
using Cassandra;
using Cassandra.Data.Linq;
using TestDatastaxCsDriver.Concrete;
namespace TestDatastaxCsDriver
{
class Program
{
static void Main(string[] args)
{
Cluster cluster =
Cluster.Builder().AddContactPoint("127.0.0.1").WithCredentials("cassandra",
"cassandra").Build();
var session = cluster.Connect();
session.CreateKeyspaceIfNotExists("test");
session.ChangeKeyspace("test");
var issuer = session.GetTable<Issuer>();
issuer.CreateIfNotExists();
}
}
}
The request would be to allow for the CreateIfNotExists method to ignore the
override keyword and to create the property with the type specified as long as
the type is one of the types supported by the driver (e.g. string, int, bool,
etc.).
Please let me know if you need more sample code or additional clarification
regarding this request.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)