This project is read-only.

EF CTP4 complied query

Aug 10, 2010 at 11: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 2: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

If I'm missing something please correct me.