How to convert Linq.ParallelQuery to Linq.IQueryable

var transactions = from t in context.Transactions group t.Create_Date_Time by t.Participation_Id into t1 select new { ParticipationId = t1.Key, CreateDateTime = t1.Max() }; var cases = from c in context.Cases group c.Create_Date_Time by c.Participation_Id into c1 select new { ParticipationId = c1.Key, CreateDateTime = c1.Max() }; var interactions = (from i in context.Interactions join pp in context.Party_Participation on i.Party_Id equals pp.Party_Id group i.Last_Update_Date_Time.HasValue ? i.Last_Update_Date_Time : i.Create_Date_Time by pp.Participation_Id into i1 select new {ParticipationId = i1.Key, CreateDateTime = i1.Max()}).AsQueryable(); 

Given the code above, the following will work

 transactions.Union(cases); 

However, the following will not work

 transactions.Union(interactions); 

Since transactions and cases are returned by Linq.IQueryable , but the last one is Linq.ParallelQuery because it joins another table.

I need this functionality mainly to create the Union. interactions.Union(transactions) or transactions.Union(interactions) one with the other.

+6
c # linq linq-to-objects linq-to-entities entity-framework
source share
3 answers

My answer to this question may not be correct, however, I raised this question primarily on the following problem. LINQ to Entities Union throws an error .

I found a fantastic answer diceguyd30 , and my problem was solved. Therefore, I close this question in response to my previous question.

+1
source share

The anonymous type of transactions and cases same. Anonymous type of interactions is another !

So, the solution is select so that the anonymous types are the same. Therefore, either create your own type or convert the selected product properties to the same type.

Something like this should call the same anonymous type for all selected:

 select new { ParticipationId = (int)c1.Key, CreateDateTime = (DateTime)c1.Max() } 
+1
source share
 interactions.Union(transactions.AsEnumerable()); 

which should work as the first parameter is IQueryable and the second is IEnumerable

 Queryable.Union<TSource> Method (IQueryable<TSource>, IEnumerable<TSource>) 
0
source share