I cannot find why the following exception occurs. Any help is most appreciated.
// EdcsEntities is derived from System.Data.Objects.ObjectContext
EdcsEntities db = new EdcsEntities();
var query = from i in db.Colleges
select i;
query = query.SkipWhile<College>(x => x.CollegeID != 100);
List<College> l = query.ToList<College>();
Exception:
LINQ to Entities does not recognize the method 'System.Linq.IQueryable
1[EDCS.ServiceLayer.DataAccess.College] SkipWhile[College](System.Linq.IQueryable
1[EDCS.ServiceLayer.DataAccess.College], System.Linq.Expressions.Expression1[System.Func
2[EDCS.ServiceLayer.DataAccess.College, System.Boolean]])' method, and this method cannot be translated into a store expression.
You can't use SkipWhile
with EF because there's no good way to translate them to SQL. Since SQL queries return unordered sets (unless you use ORDER BY
) it doesn't make sense to use predicates like that, so they don't exist.
The way to use SkipWhile
in EF is to just turn the query into objects with AsEnumerable()
before calling it:
query = query.AsEnumerable().SkipWhile(x => x.CollegeID != 100);
Of course you probably want to do something like this:
query = query.OrderBy(x => x.CollegeId).Where(x => x.CollegeID > 100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With