2

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

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

How this can be accomplished.

  • 1
    what's the type of your query result for Prod and PreProd? it is IQuerable? check this link: http://social.msdn.microsoft.com/Forums/en-US/3962b925-fe1e-4b96-ade3-5cb3b4be4511/compiledquery-exception-this-method-supports-linq-to-entity-infrastructure-and-is-not-intended-to – Tim.Tang Jul 02 '13 at 15:51

2 Answers2

4

You can use .AsEnumerable() to convert IQueryable to IEnumerable firstly.

 var Prod = this.UnitOfWork.myRepository.GetData().AsEnumerable();
 var PreProd = this.UnitOfWork.myRepository.GetData().AsEnumerable();

 var Merge = Prod.Union(PreProd);
J.W.
  • 17,991
  • 7
  • 43
  • 76
2

LINQ to EF supported Union:

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());
Tim.Tang
  • 3,158
  • 1
  • 15
  • 18