Click here to Skip to main content
15,747,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public static Func<ReviewEntities, int, IQueryable<ProjTeamMemberDetails>>
        GetTeamMembersByTeamId = CompiledQuery.Compile((ReviewEntities context, int teamId)
             => from tp in context.TeamPlayers
                join t in context.Teams on tp.TeamId equals t.ID
                join emp in context.Employees on tp.EmployeeId equals emp.ID
                where tp.TeamId == teamId && emp.IsActive == true
                orderby emp.JoiningDate
                select new ProjTeamMemberDetails
                    EmployeeName = emp.FirstName + " " + emp.LastName,
                    Email = emp.Email,
                    Designation = context.Designations.FirstOrDefault(s => s.ID == emp.DesignationId).Name,
                    NIC = emp.NIC,
                    JoiningDate = emp.JoiningDate,
                    EmployeeID = emp.ID

This is my code to create a compiled query for ADO.Net entity model framework. In the syntax "CompiledQuery.Complie((ReviewEntities", there is a strange error which say's

"The type 'ReviewEntities' cannot be used as type parameter 'TArg0' in the generic type or method 'System.Data.Linq.CompiledQuery.Compile(System.Linq.Expressions.Expression>)'. There is no implicit reference conversion from 'ReviewEntities' to 'System.Data.Linq.DataContext'."

I am unable to figure this out why this is creating error. It is not accepting first parameter that is DataContext.

Does Compiled query works in ADO.Net entity model or not?

Any help will be highly appreciated.

You are probably using the CompiledQuery of System.Data.Linq. Use System.Data.Objects instead.
Share this answer
Probably you are using DbContext. Compiled LINQ queries in 4.0 works with only ObjectContext. There was no support to DbContext unfortunately and auto-caching feature is released in later versions.
Share this answer

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