Click here to Skip to main content
11,479,841 members (48,698 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 .NET4
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 8:55am
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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.
Refer: http://stackoverflow.com/a/14290697[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 260
1 Sergey Alexandrovich Kryukov 215
2 F-ES Sitecore 175
3 Richard MacCutchan 100
4 DamithSL 65
0 Sergey Alexandrovich Kryukov 7,890
1 OriginalGriff 7,556
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 19 Sep 2014
Copyright © CodeProject, 1999-2015
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