开发者

How to convert Linq.ParallelQuery to Linq.IQueryable

开发者 https://www.devze.com 2023-02-10 13:41 出处:网络
var transactions = from t in context.Transactions group t.Create_Date_Time by t.Participation_Id into t1
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();

Considering the above code, following will work

transactions.Union(cases);

However following will not work

transactions.Union(interactions);

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开发者_如何学JAVA.


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() }


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.


interactions.Union(transactions.AsEnumerable());

that should work since the first parameter is IQueryable and the second is IEnumerable

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

精彩评论

暂无评论...
验证码 换一张
取 消