Linq conversion instructions. Linq to ParallelQuery IQueryable

c# entity-framework linq linq-to-entities linq-to-objects


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
                               into i1
                               select new {ParticipationId = i1.Key, CreateDateTime = i1.Max()}).AsQueryable();

Considering the above code, following will work


However following will not work


Because transactions and cases both are returning Linq.IQueryable but the last one is Linq.ParallelQuery due to it join with an another table.

I need this functionality basically to make Union. interactions.Union(transactions) or transactions.Union(interactions) one with other.

2/11/2011 7:38:25 PM

Accepted Answer

My answer to this question may be incorrect however I raised up this question primarly for the following problem. LINQ to Entities Union is throwing an error.

I found a fantastic reply from diceguyd30 and it was solved my problem. Hence I am closing this question in response to my previous question's answer.

5/23/2017 11:47:45 AM

Popular Answer

The anonymous type of transactions and cases is the same. The anonymous type of interactions is different!

So the solution is to select in a way that makes the anonymous types the same. So either create your own type or convert the select product's properties to the same type.

Something like this should produce the same anonymous type for all the selects:

select new { ParticipationId = (int)c1.Key, CreateDateTime = (DateTime)c1.Max() }

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow