c# Compiled Queries -
i'm trying make compiled query, following msdn example @ http://msdn.microsoft.com/en-us/library/bb896297.aspx
here code
static readonly func<newtestdbcontext, string, long, iqueryable<routequerymodel>> s_compiledquery2 = compiledquery.compile<newtestdbcontext, string, long, iqueryable<routequerymodel>>( (db, currentlocation, x) => 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 following error
error 1 type 'w.models.newtestdbcontext' cannot used type parameter 'targ0' in generic type or method 'system.data.objects.compiledquery.compile(system.linq.expressions.expression>)'. there no implicit reference conversion 'w.models.newtestdbcontext' 'system.data.objects.objectcontext'.
i'm going guess here , suggest newtestdbcontext doesn't inherit objectcontext, or you're passing wrong object?
are using entity framework ?
have tried using reference code @ bottom of page, replacing adventureworks own schema ?
http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx
hope helps!
Comments
Post a Comment