我有一种情况,我需要用逗号分隔用户的输入字符串并查询本地数据库以查找至少匹配一个子字符串的记录。
到目前为止,我没有成功,以下不起作用并抛出NotSupportedException
:
DBRef db = new DBRef { ObjectTrackingEnabled = false };
var ex = Query.ToLower( ).Split(new string[] { ", ", "," }, StringSplitOptions.RemoveEmptyEntries);
var result = (from a in db.Table where ex.Any(word => a.Title.ToLower().Contains(word)) select a).Take(50);
详细例外:
An exception of type 'System.NotSupportedException' occurred in System.Data.Linq.ni.dll and wasn't handled before a managed/native boundary
System.NotSupportedException: Local sequence cannot be used in LINQ to SQL implementations of query operators except the Contains operator.
at System.Data.Linq.SqlClient.QueryConverter.CoerceToSequence(SqlNode node)
at System.Data.Linq.SqlClient.QueryConverter.VisitQuantifier(Expression sequence, LambdaExpression lambda, Boolean isAny)
at System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitWhere(Expression sequence, LambdaExpression predicate)
at System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitTake(Expression sequence, Expression count)
at System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.ConvertOuter(Expression node)
at System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query, SqlNodeAnnotations annotations)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
这可以在 Windows Phone 上完成吗?如果可以,那怎么做?