DbSet does not contain a definition for Where

Bug Description: ‘System.Data.Entity.DbSet<>’ does not contain a definition for ‘Where’ and the best extension method overload ‘System.Linq.Queryable.Where<TSource>(System.Linq.IQueryable<TSource>, System.Linq.Expressions.Expression<System.Func<TSource,bool>>)’ has some invalid arguments

Code:

ObjectQuery<Person> studentQuery = schoolContext.People
.Where(“it.EnrollmentDate is not null”)
.OrderBy(“it.LastName”);

Workaround:

You need to use adapter to achieve this.

var studentQuery = ((IObjectContextAdapter)schoolContext).ObjectContext.CreateObjectSet<Person>()
.Where(“it.EnrollmentDate is not null”)
.OrderBy(“it.LastName”);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s