• Linq查询报Queries with local collections are not supported 错误
  • 发布于 2个月前
  • 184 热度
    1 评论

我在用LINQ做列表查询时系统报:Queries with local collections are not supported 错误。

查询的Linq代码如下:

public static IEnumerable<Model.V_RequestList> GetMyRecivedMsgList(string employeeID, V_RequestList searchCondition)
        {
            string[] nodes = new string[] { "RD", "CYX", "LOGM", "Q" };
            ESIDataContext dataContext = new ESIDataContext();
            var queryUnReadMsg = (from n in dataContext.Messages where n.HasRead == false && nodes.Contains(n.MsgTo) == true select n.TechSpecID.Value).Distinct();
            var queryMyResponsible = from n in dataContext.RequestDetails
                                     where n.CDX1EmployeeID == employeeID || (from q in dataContext.MaterialGroupSecondLevels
                                                                              where q.LOGMEmployeeID == employeeID ||
                                                                                  q.QSEmployeeID == employeeID || q.CYXEmployeeID ==employeeID
select q.Code).Distinct().Contains(n.SecondMaterialGroupCode)
select n.ID;

var query = from q in dataContext.V_RequestLists
                        where queryUnReadMsg.Contains(q.ID.Value) && queryMyResponsible.Distinct().Contains(q.ID.Value) &&
                        (string.IsNullOrEmpty(searchCondition.AppliNo) ? true : q.AppliNo.Contains(searchCondition.AppliNo)) &&
                        (string.IsNullOrEmpty(searchCondition.ProjectName) ? true : q.ProjectName.Contains(searchCondition.ProjectName)) &&
                        (string.IsNullOrEmpty(searchCondition.Description) ? true : q.Description.Contains(searchCondition.Description))
                        select q;
            return query.AsEnumerable();
        }

具体错误代码如下:

Queries with local collections are not supported Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: Queries with local collections are not supported

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NotSupportedException: Queries with local collections are not supported]
   System.Data.Linq.SqlClient.Visitor.ConvertToFetchedSequence(SqlNode node) +691564
   System.Data.Linq.SqlClient.Visitor.VisitAlias(SqlAlias a) +97
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +457
   System.Data.Linq.SqlClient.SqlVisitor.VisitSource(SqlSource source) +8
   System.Data.Linq.SqlClient.Visitor.VisitSelect(SqlSelect select) +185
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +1024
   System.Data.Linq.SqlClient.Visitor.VisitAlias(SqlAlias a) +88
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +457
   System.Data.Linq.SqlClient.SqlVisitor.VisitSource(SqlSource source) +8
   System.Data.Linq.SqlClient.Visitor.VisitSelect(SqlSelect select) +185
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +1024
   System.Data.Linq.SqlClient.SqlVisitor.VisitSequence(SqlSelect sel) +8
   System.Data.Linq.SqlClient.SqlVisitor.VisitExists(SqlSubSelect sqlExpr) +13
   System.Data.Linq.SqlClient.SqlVisitor.VisitSubSelect(SqlSubSelect ss) +39
   System.Data.Linq.SqlClient.Visitor.VisitSubSelect(SqlSubSelect ss) +94
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +934
   System.Data.Linq.SqlClient.Visitor.VisitExpression(SqlExpression expr) +12
   System.Data.Linq.SqlClient.Visitor.VisitBinaryOperator(SqlBinary bo) +437
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +196
   System.Data.Linq.SqlClient.Visitor.VisitExpression(SqlExpression expr) +12
   System.Data.Linq.SqlClient.Visitor.VisitBinaryOperator(SqlBinary bo) +456
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +196
   System.Data.Linq.SqlClient.Visitor.VisitExpression(SqlExpression expr) +12
   System.Data.Linq.SqlClient.Visitor.VisitSelect(SqlSelect select) +217
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +1024
   System.Data.Linq.SqlClient.Visitor.VisitAlias(SqlAlias a) +88
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +457
   System.Data.Linq.SqlClient.SqlVisitor.VisitSource(SqlSource source) +8
   System.Data.Linq.SqlClient.Visitor.VisitSelect(SqlSelect select) +185
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +1024
   System.Data.Linq.SqlClient.Visitor.VisitAlias(SqlAlias a) +88
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +457
   System.Data.Linq.SqlClient.SqlVisitor.VisitSource(SqlSource source) +8
   System.Data.Linq.SqlClient.Visitor.VisitSelect(SqlSelect select) +185
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +1024
   System.Data.Linq.SqlClient.Visitor.VisitAlias(SqlAlias a) +88
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +457
   System.Data.Linq.SqlClient.SqlVisitor.VisitSource(SqlSource source) +8
   System.Data.Linq.SqlClient.Visitor.VisitSelect(SqlSelect select) +185
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +1024
   System.Data.Linq.SqlClient.SqlVisitor.VisitSequence(SqlSelect sel) +8
   System.Data.Linq.SqlClient.SqlVisitor.VisitExists(SqlSubSelect sqlExpr) +13
   System.Data.Linq.SqlClient.SqlVisitor.VisitSubSelect(SqlSubSelect ss) +39
   System.Data.Linq.SqlClient.Visitor.VisitSubSelect(SqlSubSelect ss) +94
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +934
   System.Data.Linq.SqlClient.Visitor.VisitExpression(SqlExpression expr) +12
   System.Data.Linq.SqlClient.Visitor.VisitBinaryOperator(SqlBinary bo) +437
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +196
   System.Data.Linq.SqlClient.Visitor.VisitExpression(SqlExpression expr) +12
   System.Data.Linq.SqlClient.Visitor.VisitBinaryOperator(SqlBinary bo) +437
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +196
   System.Data.Linq.SqlClient.Visitor.VisitExpression(SqlExpression expr) +12
   System.Data.Linq.SqlClient.Visitor.VisitBinaryOperator(SqlBinary bo) +437
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +196
   System.Data.Linq.SqlClient.Visitor.VisitExpression(SqlExpression expr) +12
   System.Data.Linq.SqlClient.Visitor.VisitBinaryOperator(SqlBinary bo) +437
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +196
   System.Data.Linq.SqlClient.Visitor.VisitExpression(SqlExpression expr) +12
   System.Data.Linq.SqlClient.Visitor.VisitSelect(SqlSelect select) +217
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +1024
   System.Data.Linq.SqlClient.Visitor.VisitAlias(SqlAlias a) +88
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +457
   System.Data.Linq.SqlClient.SqlVisitor.VisitSource(SqlSource source) +8
   System.Data.Linq.SqlClient.Visitor.VisitSelect(SqlSelect select) +185
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +1024
   System.Data.Linq.SqlClient.Visitor.VisitAlias(SqlAlias a) +88
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +457
   System.Data.Linq.SqlClient.SqlVisitor.VisitSource(SqlSource source) +8
   System.Data.Linq.SqlClient.Visitor.VisitSelect(SqlSelect select) +185
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +1024
   System.Data.Linq.SqlClient.Visitor.VisitIncludeScope(SqlIncludeScope scope) +75
   System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) +2626
   System.Data.Linq.SqlClient.SqlBinder.Bind(SqlNode node) +26
   System.Data.Linq.SqlClient.SqlProvider.BuildQuery(ResultShape resultShape, Type resultType, SqlNode node, ReadOnlyCollection`1 parentParameters, SqlNodeAnnotations annotations) +451
   System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query, SqlNodeAnnotations annotations) +155
   System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +132
   System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute(Expression expression) +26
   System.Web.Query.Dynamic.DynamicQueryable.Count(IQueryable source) +148
   System.Web.UI.WebControls.DynamicQueryableWrapper.Count(IQueryable source) +6
   System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelectAutoSortAndPage(IQueryable source, DataSourceSelectArguments arguments) +115
   System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelectQuery(LinqDataSourceSelectEventArgs selectEventArgs, Object selectResult, Object table, Boolean storeOriginalValues) +327
   System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +457
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +19
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +72
   System.Web.UI.Control.EnsureChildControls() +87
   System.Web.UI.Control.PreRenderRecursiveInternal() +44
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842

用户评论
  • 别来无恙
  • 你的第三个查询是以第一个查询和第二个查询的结果集为查询条件的,Linq是不支持这样的操作的,你不应该定义前两个变量,而是应该直接把上面的查询语句写在同一个查询语句里,类似如下:

    var query = from q in dataContext.V_RequestLists
                            where (from t in .... select t.ID).Contains(q.ID.Value) && (form p in ....select p.ID).Distinct().Contains(q.ID.Value)  select q;


  • 2019/1/10 20:52:00 [ 0 ] [ 0 ] 回复