我想将两个 LINQ 查询结果合二为一:
var query1 = from sn in code
group sn by sn.Substring(0, 10) into g
select new
{
Key = g.Key,
Cnt = g.Count(),
Min = g.Min(v => v.Substring(10, 4)),
Max = g.Max(v => v.Substring(10, 4))
};
var query2 = from sn1 in codes
group sn1 by sn1.Substring(0, 11) into g
select new
{
key = g.Key,
Cnt = g.Count(),
Min = g.Min(v => v.Substring(11, 4)),
max = g.Max(v => v.Substring(11, 4))
};
var query3= query1.Union(query2)
但在编译时出现错误:
“
System.Collections.Generic.IEnumerable<AnonymousType#1>
”不包含“ ”的定义Union
并且最佳扩展方法重载“System.Linq.Queryable.Union<TSource>(System.Linq.IQueryable<TSource>, System.Collections.Generic.IEnumerable<TSource>)
”有一些无效参数
我的代码有什么问题?