Reputation: 415
I've just upgraded the driver from 2.7.3 to 3.0.3 and seems like something weird was done with the Mapper.Single() . It was just working on the old version but now throws an exception;
Exception thrown: 'System.ArgumentException' in Cassandra.dll ("Argument types do not match")
Schema:
CREATE TABLE IF NOT EXISTS client (
id uuid PRIMARY KEY,
timezone frozen<timezone>,
language frozen<language>,
bank set<frozen<bank>>,
name text,
country frozen<country>
);
CREATE TYPE IF NOT EXISTS timezone (
id uuid,
name text,
time int
);
CREATE TYPE IF NOT EXISTS language (
id uuid,
name text,
iso text
);
CREATE TYPE IF NOT EXISTS bank (
id uuid,
name text,
number int
);
CREATE TYPE IF NOT EXISTS country (
id uuid,
name text,
iso2 text,
iso3 text
);
Mappings
For<Client>()
.TableName("client")
.PartitionKey(u => u.Id)
.Column(u => u.Id, cm => cm.WithName("id"))
.Column(u => u.Name, cm => cm.WithName("name").WithSecondaryIndex())
.Column(u => u.Timezone, cm => cm.WithName("timezone"))
.Column(u => u.Language, cm => cm.WithName("language"))
.Column(u => u.Country, cm => cm.WithName("country"))
.Column(u => u.Banks, cm => cm.WithName("bank"));
UdtMap.For<Timezone>()
.Map(u => u.Id, "id")
.Map(u => u.Name, "name")
.Map(u => u.Time, "time")
UdtMap.For<Bank>()
.Map(u => u.Id, "id")
.Map(u => u.Number, "number")
.Map(u => u.Name, "name")
UdtMap.For<Language>()
.Map(u => u.Id, "id")
.Map(u => u.Name, "name")
.Map(u => u.Iso, "iso")
UdtMap.For<Country>()
.Map(u => u.Id, "id")
.Map(u => u.Name, "name")
.Map(u => u.Iso2, "iso2")
.Map(u => u.Iso3, "iso3")
C# Code
public static class CassandraConnection
{
private static Cluster Cluster;
public static String Keyspace { get; set; }
public static String[] Addresses { get; set; }
public static String Username { get; set; }
public static String Password { get; set; }
public static ISession Session { get; set; }
public static MappingConfiguration MappingConfiguration { get; set; }
public static IMapper Mapper { get; set; }
public static void Conectar()
{
Addresses = CloudConfigurationManager.GetSetting("Cassandra.Addresses").Split(';');
Keyspace = CloudConfigurationManager.GetSetting("Cassandra.Keyspace");
Username = CloudConfigurationManager.GetSetting("Cassandra.Username");
Password = CloudConfigurationManager.GetSetting("Cassandra.Password");
if (String.IsNullOrEmpty(Username))
{
CassandraConnection.Cluster = Cluster.Builder().AddContactPoints(Addresses).Build();
}
else
{
CassandraConnection.Cluster = Cluster.Builder().AddContactPoints(Addresses).WithCredentials(Username, Password).Build();
}
CassandraConnection.Session = CassandraConnection.Cluster.Connect(Keyspace);
MappingConfiguration.Global.Define<MapCassandra>();
Session.UserDefinedTypes.Define(UdtCassandra.Udts());
CassandraConnection.Mapper = new Mapper(CassandraConnection.Session);
}
}
public class CassandraRepository<T> : IRepository<T> where T : BaseDomain
{
public T GetById(T entity)
{
if(CassandraConnection.Session == null)
{
CassandraConnection.Conectar();
}
if (entity != null)
{
return CassandraConnection.Mapper.Fetch<T>("WHERE id = ?", entity.Id).FirstOrDefault(); //That should be just SingleOrDefault() but im testing stuff;
}
return default(T);
}
}
StackTrace
em System.Linq.Expressions.Expression.Condition(Expression test, Expression ifTrue, Expression ifFalse)
em Cassandra.Mapping.MapperFactory.GetExpressionToGetColumnValueFromRow(ParameterExpression row, CqlColumn dbColumn, Type pocoDestType)
em Cassandra.Mapping.MapperFactory.CreateMapperForPoco[T](RowSet rows, PocoData pocoData)
em Cassandra.Mapping.MapperFactory.CreateMapper[T](RowSet rows)
em Cassandra.Mapping.MapperFactory.<>c__DisplayClass1`1.<GetMapper>b__0(Tuple`2 _)
em System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
em Cassandra.Mapping.MapperFactory.GetMapper[T](String cql, RowSet rows)
em Cassandra.Mapping.Mapper.<>c__DisplayClass7`1.<FetchAsync>b__6(Statement s, RowSet rs)
em Cassandra.Mapping.Mapper.<>c__DisplayClass2`1.<>c__DisplayClass4.<ExecuteAsyncAndAdapt>b__1(Task`1 t2)
em Cassandra.Tasks.TaskHelper.DoNext[TIn,TOut](Task`1 task, Func`2 next)
em Cassandra.Tasks.TaskHelper.WaitToComplete(Task task, Int32 timeout)
em Cassandra.Tasks.TaskHelper.WaitToComplete[T](Task`1 task, Int32 timeout)
em Cassandra.Mapping.Mapper.Fetch[T](Cql cql)
em Cassandra.Mapping.Mapper.Fetch[T](String cql, Object[] args)
em CassandraWebTest.Repository.Cassandra.CassandraRepository`1.GetById(T entity) na C:\Users\devb0194\Source\Workspaces\CassandraWebTestV3\CassandraWebTest.Repository\Cassandra\CassandraRepository.cs:linha 124
em CassandraWebTest.Business.Security.Client.GetById(Client Client) na C:\Users\devb0194\Source\Workspaces\CassandraWebTestV3\CassandraWebTest.Business\Security\Client.cs:linha 63
em CassandraWebTest.Business.Security.UsuarioAutenticacao.Authenticate(UsuarioAutenticacao usuarioAutenticacao) na C:\Users\devb0194\Source\Workspaces\CassandraWebTestV3\CassandraWebTest.Business\Security\UsuarioAutenticacao.cs:linha 95
em CassandraWebTest.Web.Controllers.LoginController.Authenticate(String usuario, String senha, Boolean persistente) na C:\Users\devb0194\Source\Workspaces\CassandraWebTestV3\Web\CassandraWebTest.Web\Controllers\LoginController.cs:linha 38
This code works fast and perfectly on 2.7.X but doesnt work on 3.X.X drivers.
Upvotes: 1
Views: 866
Reputation: 415
Error was due one of the POCO's got a reference to a frozen type using IList instead IEnumerable.
That used to work on 2.7.X but doesnt work on 3.X.X.
Thanks a lot Jorge!
Upvotes: 2