LINQ query getting runtime error

I have this linq query and am using EF edmx.

        forms = (from f in db.Forms
                 join ffl in db.FormFirstLetters on f.FormID equals ffl.FormID
                 where f.IsActive
                 where criteria.CategoryNames == null || criteria.CategoryNames.Contains(f.Category)
                 where startsWith == null || startsWith.Contains(ffl.FirstLetter)
                 orderby f.FormName
                 select new FormSummary
                 {
                     FormID = f.FormID,
                     Category = f.Category,
                     FormName = f.FormName,
                     AcceptSubmissions = f.AcceptSubmissions,
                     TodaysEntries = f.FormSubmissions.Count(tbl => tbl.SubmissionDate >= todaysDate),
                     TotalEntries = f.FormSubmissions.Count(),
                     LatestEntry = f.FormSubmissions.OrderByDescending(x => x.SubmissionDate).Select(x => x.SubmissionDate).FirstOrDefault()
                 }).ToArray();

I am getting this error

Unable to create a constant value of type 'System.Collections.Generic.IEnumerable`1'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.

I thought using Contains was acceptable and have used it many times before in these types of linq queries but for some reason it is not working. Both criteria.CategoryNames and startsWith are IEnumerable<string> and the field being searched for are strings. Why is this not working?

Answers


Had a value in one of the lists that was an empty string. Apparently EF doesn't know how to translate that to sql? Wow.


Need Your Help

C++11 exception design. Idioms and best practices changed?

c++ c++11 exception-handling

I am wondering if, since C++11, where passing exceptions between threads was added and nested exceptions were added, idioms changed for exception capturing, in general.

setRetainInstance(boolean) method in fragments

android android-fragments

Its known from docs that setRetainInstance(boolean) method helps retains all active objects across device configuration changes, but most of the examples and documentations I read deals with headless