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?
You’re using the wrong
CompiledQuery. There is one for L2S and another for L2E. It’s the latter you want. Check yourusingstatement at the top of the file.