1
votes

I'm trying to pre-compile queries in my Entity Framework application using my entities object.

I receive an error stating that There is no implicit reference conversion from myEntities to System.Data.Linq.DataContext.

An example of my compiled query is below. myEntities inherits 'ObjectContext', which is probably the root of the problem but I'm not sure why.

    //Compiled Version
    public static Func<myEntities, Users_GetUsersInRoleInputs, IQueryable<UserRole>> FilteredResult =

               CompiledQuery.Compile<myEntities, Users_GetUsersInRoleInputs, IQueryable<UserRole>>(

               (myEntities, Users_GetUsersInRoleInputs criteria) =>
                   (from t1 in dc.UserRoles
                   where (t1.Role_ID == criteria.RoleId)
                   select t1));

    public class Users_GetUsersInRoleInputs
    {
        public int RoleId { get; set; }
        public int CompanyId { get; set; }
    }

Could anybody suggest why this might be and how I can use query compilation in my project?

1
myEntities inherits ObjectContext - sorry if that wasn't clear. - Nick
so it is a class? not an instantiated class? - Joe
It's a partial class and contained within the designer of my EDMX file - Nick
Shouldn't (myEntities, Users_GetUsersInRoleInputs criteria) be (myEntities dc, Users_GetUsersInRoleInputs criteria)? - Jakub Januszkiewicz
what is dc ? Any why is myEntities a class name and a parameter name? - springy76

1 Answers

3
votes

You're using the wrong CompiledQuery. There is one for L2S and another for L2E. It's the latter you want. Check your using statement at the top of the file.