c# - Cassandra:参数类型不匹配

标签 c# linq cassandra nosql-aggregation nosql

我是 Cassandra 的新手,使用 linq 为我的 Cassandra 数据库创建了一个通用存储库。对于我的 Single() 方法,我将 where 条件作为参数传递。

这是我的单一方法:

Single(Expression<Func<T, bool>> exp)

这是我用来查询cassandra数据库的linq代码

public async Task<T> Single(Expression<Func<T, bool>> exp)
{
    return await GetTable.Where<T>(exp).FirstOrDefault().ExecuteAsync();
}

这是调用单一方法的方法

public override Task OnConnected()
{
    if (Context.User != null)
    {
        string userName = Context.User.Identity.Name;

        this.Groups.Add(userName, Context.ConnectionId);

        ***** this is the line with the issue ******
        Notification notification = Task.Run(() => _notificationRepository.Single(x => x.UserName.Equals(userName))).Result;

        if (notification == null)
        {
            _notificationRepository.CreateInstance(new NotificationUserMapping { Connections = new string[] { Context.ConnectionId }, UserName = Context.User.Identity.Name });
        }
        else if (!notification.Connections.Contains(Context.ConnectionId))
        {
            notification.Connections.Add(Context.ConnectionId);
            _notificationRepository.Save(notification);
        }
    }

    return base.OnConnected();
}

我不断收到“参数类型不匹配”的“System.AggregateException”,我很困惑这可能是从哪里来的。

数据库表列:

id uuid PRIMARY KEY,
connections list<text>,
username text

和 c# poco:

[Table(ExplicitColumns = true)]
public class ConnectionMapping
{
    [Column("id")]
    public Guid Id { get; set; }
    [Column("connections")]
    public IList<string> Connections { get; set; }
    [Column("username")]
    public string UserName { get; set; }
}

和异常:

   at System.Linq.Expressions.Expression.Condition(Expression test, Expression ifTrue, Expression ifFalse)
   at Cassandra.Mapping.MapperFactory.GetExpressionToGetColumnValueFromRow(ParameterExpression row, CqlColumn dbColumn, Type pocoDestType)
   at Cassandra.Mapping.MapperFactory.CreateMapperForPoco[T](RowSet rows, PocoData pocoData)
   at Cassandra.Mapping.MapperFactory.CreateMapper[T](RowSet rows)
   at Cassandra.Mapping.MapperFactory.<>c__DisplayClass1`1.<GetMapper>b__0(Tuple`2 _)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Cassandra.Mapping.MapperFactory.GetMapper[T](String cql, RowSet rows)
   at Cassandra.Mapping.Mapper.<>c__DisplayClass7`1.<FetchAsync>b__6(Statement s, RowSet rs)
   at Cassandra.Mapping.Mapper.<>c__DisplayClass2`1.<>c__DisplayClass4.<ExecuteAsyncAndAdapt>b__1(Task`1 t2)
   at Cassandra.Tasks.TaskHelper.DoNext[TIn,TOut](Task`1 task, Func`2 next)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at CompanyNamespace.CompanyDomain.NotificationRepository.<SingleByUserName>d__0.MoveNext()

我错过了什么。我审查了文档。以及 Cassandra 和 c# 之间的映射规则,一切似乎都是正确的。

最佳答案

通过一些实验,我找到了答案。来发现基于 Cassandra 列表的集合不映射到 c# 列表,而是映射到 c# IEnumerable 对象。

关于c# - Cassandra:参数类型不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38793591/

相关文章:

c# - 什么是界面鸭子类型?

c# - 如何在我的网站中使用 PDFsharp 中的字体?

c# - Entity Framework - 在 Linq 中处理空值

java - 当我们尝试检索大数据时 Cassandra 服务器崩溃

database - Cassandra 数据中心复制与 Couchbase 数据中心复制

C# MongoDB - 编辑嵌套 2 层的数据

c# - 一旦第二个窗口关闭,属性就会恢复为原始值

c# - 在 LINQ 查询中的模型值中使用列表

linq - 如何在 linq 中进行聚合查询

Cassandra 1.1 或 1.2 用于生产用途?