Concat两个具有匿名类型的IQueryables? [英] Concat Two IQueryables with Anonymous Types?

查看:121
本文介绍了Concat两个具有匿名类型的IQueryables?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经努力了好一阵子,而且开始看起来似乎不可能.

I've been wrestling with this a little while and it's starting to look like it may not be possible.

我要Concat()两个IQueryable,然后将结果作为单个查询执行.我尝试过这样的事情:

I want to Concat() two IQueryables and then execute the result as a single query. I tried something like this:

var query = from x in ...
select new
{
    A = ...
    B = ...
    C = ...
};

var query2 = from y in ...
select new
{
    A = ...
    B = ...
    C = ...
};

var query3 = query.Concat(query2);

但是,最后一行给我以下错误:

However, the last line gives me the following error:

'System.Linq.IQueryable'不包含'Concat'的定义,最佳扩展方法重载'System.Linq.ParallelEnumerable.Concat(System.Linq.ParallelQuery,System.Collections.Generic.IEnumerable)'具有一些无效的参数

'System.Linq.IQueryable' does not contain a definition for 'Concat' and the best extension method overload 'System.Linq.ParallelEnumerable.Concat(System.Linq.ParallelQuery, System.Collections.Generic.IEnumerable)' has some invalid arguments

似乎该参数期望为IEnumerable.有什么办法解决吗?

It appears it's expecting an IEnumerable for the argument. Is there any way around this?

看起来我可以将两个查询都解析为IEnumerable s,然后将它们解析为Concat().但是创建单个查询会更有效,而且似乎应该可行.

It looks like I could resolve both queries to IEnumerables and then Concat() them. But it would be more efficient to create a single query, and it seems like that should be possible.

推荐答案

正如您之前在评论中所述,看来这两个查询返回的对象不同:

As you said previously in the comments, it seems that the two queries return different objects:

查询1(根据评论):

f__AnonymousTypee<Leo.Domain.FileItem,Leo.Domain.Employ‌​ee,int,string,string>

Query2是

f__AnonymousTypee<Leo.Domain.FileItem,L‌​eo.Domain.Employee,int?,string,string>

这就是为什么Concat会向您显示一条错误消息,抱怨参数无效.

This is why Concat is giving you an error message complaining about invalid arguments.

这篇关于Concat两个具有匿名类型的IQueryables?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆