我正在编写一个查询,该查询需要在 realm.xamarin linq 查询中使用类似“WHERE IN”的子句。以下是我尝试的查询:
var IdsToMatch = observations.Select(x => x.Id)
var results = from d in realm.All<Observations>() where IdsToMatch.Any(p => p == d.Id) select d;
也试过这个Contains
:
var results = from d in realm.All<Observations>() where IdsToMatch.Contains(d.Id) select d;
但这会引发错误:
The method 'Contains' is not supported
The method 'Any' is not supported
解决方案是什么?
编辑 :
这是错误的堆栈跟踪:
未处理的异常:06-07 15:04:55.097 I/MonoDroid(24526):System.NotSupportedException:不支持“任何”方法 06-07 15:04:55.097 I/MonoDroid(24526):在 Realms.RealmResultsVisitor。 VisitMethodCall (System.Linq.Expressions.MethodCallExpression m) [0x00596] in :0 06-07 15:04:55.097 I/MonoDroid(24526): 在 Realms.ExpressionVisitor.Visit (System.Linq.Expressions.Expression exp) [0x000ec ] 在:0 06-07 15:04:55.097 I/MonoDroid(24526):在 Realms.RealmResultsVisitor.VisitMethodCall (System.Linq.Expressions.MethodCallExpression m) [0x0006a] 在:0 06-07 15:04:55.097 I /MonoDroid(24526): 在 Realms.ExpressionVisitor.Visit (System.Linq.Expressions.Expression exp) [0x000ec] 在:0 06-07 15:04:55.097 I/MonoDroid(24526): 在 Realms.RealmResults
1[T].CreateResultsHandle () [0x00037] in <filename unknown>:0 06-07 15:04:55.097 I/MonoDroid(24526): at Realms.RealmResults
1[T].get_ResultsHandle () [0x0000d] in :0 06-07 15:04:55.097 I/MonoDroid(24526): 在 Realms.RealmResults1[T].GetEnumerator () [0x00000] in <filename unknown>:0 06-07 15:04:55.097 I/MonoDroid(24526): at System.Collections.Generic.List
1[T]..ctor (IEnumerable1 collection) [0x00073] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/collections/generic/list.cs:104 06-07 15:04:55.098 I/MonoDroid(24526): at System.Linq.Enumerable.ToList[TSource] (IEnumerable
1 source) [0x00011] in /用户/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/System.Core/System/Linq/Enumerable.cs:835 06-07 15:04:55.098 I/MonoDroid(24526):在 VHS .MobileApp.Mediq.DataAccess.ObservationDatabase+<>c__DisplayClass13.b__8 () [0x00147] in d:\rwagh\mediq\Code\VHS.MobileApp.Mediq.DataAccess\ObservationDatabase.cs:65 06-07 15:04:55.098 我/MonoDroid(24526):1[TResult].InnerInvoke () [0x00012] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/threading/Tasks/Future.cs:686 06-07 15:04:55.098 I/MonoDroid(24526): at System.Threading.Tasks.Task.Execute () [0x00016] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/threading/Tasks/Task.cs:2523 06-07 15:04:55.098 I/MonoDroid(24526): --- End of stack trace from previous location where exception was thrown --- 06-07 15:04:55.098 I/MonoDroid(24526): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 06-07 15:04:55.098 I/MonoDroid(24526): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201 06-07 15:04:55.098 I/MonoDroid(24526): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170 06-07 15:04:55.098 I/MonoDroid(24526): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142 06-07 15:04:55.098 I/MonoDroid(24526): at System.Runtime.CompilerServices.TaskAwaiter
在 /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system 中的 System.Threading.Tasks.Task 1[TResult].GetResult () [0x00000] /runtime/compilerservices/TaskAwaiter.cs:372
编辑 2:
var IdsToMatch = observations.Select(x => x.Id)
var results = from d in realm.All<Observations>() where IdsToMatch.Any(p => p == d.Id) select d;
试过:var IdsToMatch = observations.Select(x => x.Id).AsQueryable()
根据https://github.com/realm/realm-dotnet/blob/7187390529201ba843cd105fc6e3e11acb0c6217/Realm.Shared/linq/RealmResultsVisitor.cs#L121说
internal override Expression VisitMethodCall(MethodCallExpression m)
{
if (m.Method.DeclaringType == typeof(Queryable)) { ...
但这也没有用。