I'm trying to make a compiled query, following the MSDN example at http://msdn.microsoft.com/en-us/library/bb896297.aspx
Here is my code
static readonly Func<newTestDBContext, string, long, IQueryable<RouteQueryModel>> s_compiledQuery2 =
CompiledQuery.Compile<newTestDBContext, string, long, IQueryable<RouteQueryModel>>(
(db, currentLocation, x) =>
from b in db.routes
let avg_rating = b.ratings.Any() ?
b.ratings.Select(r => r.rating1).Average() :
0
let coorCount = b.coordinates.Count()
let is_favorite = b.favorites.Any(c => c.users_id == x) ?
true :
false
let distance_to_first_from_me = b.coordinates.
Select(c => c.position).
FirstOrDefault().
Distance(DbGeography.FromText(currentLocation, 4326))
let distance_to_last_from_me = b.coordinates.
OrderByDescending(c => c.sequence).
Select(d => d.position).
FirstOrDefault().
Distance(DbGeography.FromText(currentLocation, 4326))
let distance_to_from_me = distance_to_first_from_me < distance_to_last_from_me ?
distance_to_first_from_me :
distance_to_last_from_me
select new RouteQueryModel
{
b = b,
distance_to_from_me = distance_to_from_me.Value,
avg_rating = avg_rating,
coorCount = coorCount,
is_favorite = is_favorite
}
);
I'm getting the following error
Error 1 The type 'W.Models.newTestDBContext' cannot be used as type parameter 'TArg0' in the generic type or method 'System.Data.Objects.CompiledQuery.Compile(System.Linq.Expressions.Expression>)'. There is no implicit reference conversion from 'W.Models.newTestDBContext' to 'System.Data.Objects.ObjectContext'.