2016-08-05 21 views
3

私はCassandraの初心者です。linqを使用してCassandraデータベース用の汎用リポジトリを作成しました。私のSingle()メソッドでは、whereの条件をパラメータとして渡しています。Cassandra:引数の型が一致しません

これは私の独身の方法である:これは、私はこれは、単一のメソッドを呼び出す方法です

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

カサンドラデータベースに照会するために使用していますLINQコードがある

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

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オブジェクトにマップします。

関連する問題