EF CTP4 complied query

Aug 10, 2010 at 10:31 PM

I am working on using DbContext instead of ObjectContext which comes in EF CTP4.  I got everything working except compliled query is broken. 


    public class UserByNameQuery : QueryBase<User>
        private static readonly Expression<Func<DbContext, string, User>> expression = (database, name) => database.Users.SingleOrDefault(user => user.Username == name);
        private static readonly Func<DbContext, string, User> plainQuery = expression.Compile();
        private static readonly Func<DbContext, string, User> compiledQuery = CompiledQuery.Compile(expression);


I get error:  There is no implicit reference conversion from DbContext to ObjectContext. 

Thanks for the help

Sep 13, 2010 at 1:01 AM

As far as I know you must use a class that derives from ObjectContext! DbContext is not and can't be used with CompiledQuery.

Have a look at CompiledQuery class documentation at MSDN http://msdn.microsoft.com/en-us/library/system.data.objects.compiledquery.aspx

If I'm missing something please correct me.