Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
0 down vote
favorite


I am using CompiledQuery.Compile method which is been pointed by a delegate (Func) as below. This query runs fine independently, however fails with error when executed in Compile method:
System.InvalidOperationException

Message - "Member access 'System.Data.Objects.DataClasses.EntityCollection`1[Assess] of Patient not legal on type 'System.Data.Objects.ObjectQuery`1 [Patient]"

Appreciate your inputs at earliest.


C#
public Func  < DataContext, DataWarehouseEntities, DateTime, DateTime, int, IEnumerable<object> >
       getItems = CompiledQuery.Compile((DataContext db, DataWarehouseEntities dc, DateTime stopdate, DateTime prevModDate, int batchSize)

           => dc.Patient
                .Include("M30")
                .Select(a => new
                {
                    Patient = a,
                    ModDate = a.Assess.Max(x => x.ModDate),
                    M30 = a.M30,
                    Assess = a.Assess,
                    Details = a.Assess.Select(x => new
                    {
                        x.Key,
                        x.Team
                    })
                })
                .Where(a => a.ModDate >= prevModDate && a.ModDate < stopdate)
                .OrderBy(a => a.ModDate)
                .Take(batchSize) - // batch size is 1000
               .ToList()
           );


What I have tried:

This query runs fine independently, however fails when running under Compile method.
Posted
Updated 4-Apr-16 23:31pm
v2
Comments
chint.99 5-Apr-16 9:15am    
Thanks Andy, I am too seeing this post i submitted the query, not sure whether it got created when the page was posted.
Andy Lanng 5-Apr-16 9:17am    
It's from the stack-overflow post. I linked it in the comment to our experts can check if it's been answered or not.
Personally, I have very little experience with the query compilers so I can't help
chint.99 5-Apr-16 13:29pm    
Thanks Andy. That's correct, Stack overflow query has been posted by me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900