子集至少所有元素查找對象我有簡單類型Question
:其中包含使用RavenDB和LINQ
public class Question
{
public Question(string id)
{
Id = id;
Tags = new List<string>();
}
public string Id { get; private set; }
public IList<string> Tags { get; set; }
}
我已經定義了這樣的問題,標本採集:
var q1 = new Question("q1") { Tags = new List<string>() {"aa", "bb"} };
var q2 = new Question("q2") { Tags = new List<string>() {"aa"} };
var q3 = new Question("q3") { Tags = new List<string>() {"aa", "bb", "cc"} };
var q4 = new Question("q4");
var questions = new List<Question>() {q1, q2, q3, q4};
現在我需要找到所有問題,其中至少包含來自給定子集的所有標籤。子集定義如下:
string[] tags = new[] {"aa", "bb"};
,我使用的查詢,以獲得期望的結果是:
var result = questions.Where(x => !tags.Except(x.Tags).Any()).ToList();
結果是2個問題的清單:Q1和Q3,其正常工作,而我正在使用linq-to-objects。
不幸的是,當我試圖詢問這些問題,目前已堅持RavenDB,我得到一個異常:
var result = DocumentSession.Query<Question>()
.Where(x => !tags.Except(x.Tags).Any()).ToList();
結果:
System.InvalidOperationException: Cannot understand how to translate value(Core.Commands.GetQuestions+<>c__DisplayClass0).tags.Except(x.Tags)
at Raven.Client.Linq.RavenQueryProviderProcessor`1.GetPath(Expression expression, String& path, Type& memberType, Boolean& isNestedPath)
at Raven.Client.Linq.DynamicQueryProviderProcessor`1.GetMember(Expression expression)
at Raven.Client.Linq.RavenQueryProviderProcessor`1.VisitAny(MethodCallExpression expression)
at Raven.Client.Linq.RavenQueryProviderProcessor`1.VisitEnumerableMethodCall(MethodCallExpression expression)
at Raven.Client.Linq.RavenQueryProviderProcessor`1.VisitMethodCall(MethodCallExpression expression)
at Raven.Client.Linq.RavenQueryProviderProcessor`1.VisitExpression(Expression expression)
at Raven.Client.Linq.RavenQueryProviderProcessor`1.VisitExpression(Expression expression)
at Raven.Client.Linq.RavenQueryProviderProcessor`1.VisitQueryableMethodCall(MethodCallExpression expression)
at Raven.Client.Linq.RavenQueryProviderProcessor`1.VisitMethodCall(MethodCallExpression expression)
at Raven.Client.Linq.RavenQueryProviderProcessor`1.VisitExpression(Expression expression)
at Raven.Client.Linq.RavenQueryProviderProcessor`1.GetLuceneQueryFor(Expression expression)
at Raven.Client.Linq.RavenQueryProviderProcessor`1.Execute(Expression expression)
at Raven.Client.Linq.DynamicRavenQueryProvider`1.Execute(Expression expression)
at Raven.Client.Linq.DynamicRavenQueryProvider`1.System.Linq.IQueryProvider.Execute(Expression expression)
at Raven.Client.Linq.RavenQueryInspector`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
...
如何執行我想使用RavenDB?
不熟悉烏鴉驅動程序,但是嘗試不同的情況:例如包含,相交... – Tigran 2012-04-12 09:48:03