2016-08-05 190 views
3

我是Cassandra的新手,並使用linq爲我的Cassandra數據庫創建了一個通用存儲庫。對於我的Single()方法,我傳遞了where條件作爲參數。Cassandra:參數類型不匹配

這是我的一個方法:

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

這是我使用查詢卡珊德拉數據庫

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

這是調用一個方法,該方法的LINQ代碼

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#之間的映射規則似乎是正確的。

+0

你能展示整個方法嗎?很難說什麼時候你只提供小片段。 – DavidG

+0

您是否還可以爲您收到的'AggregateException'內的異常添加堆棧跟蹤?可能將我們指向正確的方向。 –

回答

2

通過一些實驗,我找到了答案。來找出Cassandra基於列表的集合不會映射到c#列表,而是映射到c#IEnumerable對象。

相關問題