指定的轉換無效。LinqToSql查詢中指定的轉換無效
OrderItemState是enum。
IEnumerable<OrderItemState> states = ...;
IEnumerable<byte> stateIds = Enumerable.Cast<byte>(states);
List<OrderEntry> entries =
(from m in dc.OrderItemMotions
where stateIds.Contains(m.OrderItemStateId)
select ...).ToList();
爲什麼?棧跟蹤的
部分:
在System.Linq.Enumerable.d__b1
1.MoveNext() at System.Linq.Enumerable.<OfTypeIterator>d__aa
1.MoveNext() 在System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Collections.Generic.List
1..ctor(IEnumerable的1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable
1源) 在System.Data.Linq.SqlClient.QueryConverter.VisitContains(Expression sequence,Expression value) at System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression節點) at System.Data.Linq.SqlClient.Que ryConverter.Visit(表達式節點) 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.VisitInner處System.Data.Linq.SqlClient.QueryConverter.VisitWhere(表達式序列,LambdaExpression謂詞) (表達式節點) 在System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression MC) System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) at System.Data.Linq.SqlClient.QueryConverter.VisitGroupBy(Expression sequence,LambdaExpression keyLambda,LambdaExpression elemLambda,LambdaExpression resultSelector) at System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) at System.Data.Linq.SqlClient.QueryConverter.VisitJoin(Expression outerSequence ,表達innerSequence,LambdaExpression outerKeySelector,LambdaExpression innerKeySelector,LambdaExpression resultSelector) 在System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression MC) 在System.Data.Linq.SqlClient.QueryConverter.VisitInner(表達在系統節點) .Data.Linq.SqlClient.QueryConverter.ConvertOuter(表達式節點) at System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query,SqlNodeAnnotations annotations) at System.Data.Linq.SqlClie nt.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(表達式查詢) 在System.Data.Linq.DataQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Collections.Generic.List
1..ctor(IEnumerable的1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable
1源)
你肯定枚舉的支持類型是:
如果它不會工作:
其能否正常工作事實上是一個'字節'?如果沒有,你需要做'雙重轉換',例如'(byte)(int)enumvalue'。 – leppie 2012-07-13 08:54:30