Click here to Skip to main content
12,997,185 members (72,880 online)
Rate this:
Please Sign up or sign in to vote.
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.
Posted 14-Sep-12 7:55am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You are probably using the CompiledQuery of System.Data.Linq. Use System.Data.Objects instead.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 19 Sep 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100