English 中文(简体)
利用联盟系统
原标题:Using Union with System.Linq.IQueryable

我试图在我的法典中使用工会:

var qryQuestions =
    (from q in db.table1
    where q.ID == ID
       && q.categoryID == categoryID
    orderby q.questionOrder ascending
    select q) .Union
        (from qp in db.table2
        where qp.ID == ID
           && qp.categoryID == categoryID
        orderby qp.questionOrder ascending
        select qp);

我收到错误信息:

第15系统,Linq.IOrdered Queryable<table1>不含联邦定义和超载最佳推广方法 System.Linq.ParallelE amountable.Union<TSource>System.Linq.Parallel Query<TSource> 系统、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、专业、

以及

误差30 理由:不能从中转 System.Linq.IOrdered Queryable<table1> to System.Linq.Parallel Query<table2>

问题回答

这是因为你正在选择两套不同的数据,林克可以不理解你试图做什么。

选择qp

var qryQuestions = (from q in db.table1
                where q.ID == ID && q.categoryID == categoryID
                select new {questionOrder= q.questionOrder, value2 = q.Value2})
               .Union
               (from qp in db.table2
                where qp.ID == ID && qp.categoryID == categoryID
                select new {questionOrder= qp.questionOrder, value2 = qp.Value2}))
               .OrderBy(x => x.questionOrder);

其原因是,你试图从同一个桌子中挑选出所有不同的实体,即:q !

如果你在命令之前完成工会,会发生什么情况?

var qryQuestions = (from q in db.table1
                    where q.ID == ID && q.categoryID == categoryID
                    select q)
                   .Union
                   (from qp in db.table2
                    where qp.ID == ID && qp.categoryID == categoryID
                    select qp)
                   .OrderBy(x => x.questionOrder);

虽然Kelvin的回答部分正确(工会的两部分必须具有相同类型/属性),但I Query的同义。 工会使用一个可计算参数。 如下。

var qryQuestions = (from q in db.table1
                where q.ID == ID && q.categoryID == categoryID
                select new {questionOrder= q.questionOrder, value2 = q.Value2})
               .Union
               ((from qp in db.table2
                 where qp.ID == ID && qp.categoryID == categoryID
                 select new {questionOrder= qp.questionOrder, value2 = qp.Value2})
                .AsEnumerable())
               .OrderBy(x => x.questionOrder);




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签