[英]Merging two Query Results
I have following two Queries on Same Table and need to merge it. 我在同一张表上有以下两个查询,需要将其合并。
var Prod = this.UnitOfWork.myRepository.GetData();
var PreProd = this.UnitOfWork.myRepository.GetData();
var Merge = Prod.Union(PreProd);
But when i check results of Merge it doesn't show Union but shows following message 但是当我检查Merge的结果时,它不显示Union而是显示以下消息
Message: This method supports the LINQ to Query Result Union not working Entities infrastructure and is not intended to be used directly from your code 消息:此方法支持LINQ查询结果联盟不起作用的实体基础结构,并且不能直接在您的代码中使用
How this can be accomplished. 如何做到这一点。
You can use .AsEnumerable() to convert IQueryable to IEnumerable firstly. 您可以使用.AsEnumerable()首先将IQueryable转换为IEnumerable。
var Prod = this.UnitOfWork.myRepository.GetData().AsEnumerable();
var PreProd = this.UnitOfWork.myRepository.GetData().AsEnumerable();
var Merge = Prod.Union(PreProd);
LINQ to EF supported Union : LINQ to EF支持的联盟 :
IQueryable<TSource> Union<TSource>(
this IQueryable<TSource> source1,
IEnumerable<TSource> source2
)
so try: 所以尝试:
var Prod = this.UnitOfWork.myRepository.GetData();
var PreProd = this.UnitOfWork.myRepository.GetData();
var Merge = Prod.Union(PreProd.AsEnumerable());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.