Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8236159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:03:42+00:00 2026-06-07T19:03:42+00:00

I have the following LINQ query in an application. The data source is a

  • 0

I have the following LINQ query in an application. The data source is a List<Borehole> constructed in memory for testing purposes.

var lq = from p in data
         group p by p.CostCenter into g
         select new {  CostCenter = g.Key, 
                       AverageDepth = g.Average(p => p.OriginalDepth),
                       NullDepthCount = g.Count(p => p.OriginalDepth == null) };

It runs perfectly and gives the desired selection result. However, when I run the following query in LINQPad, it results in InvalidOperationException:

var lq = from p in Boreholes
          group p by p.CostCenter into g
          select new {  CostCenter = g.Key, 
                        AverageDepth = g.Average(p => p.OriginalDepth),
                        NullDepthCount = g.Count(p => p.OriginalDepth == null) };

Here the data source is a table in a SQLite database, linked to LINQPad using the IQ 2.0.5.0 LINQPad driver. The error message is:

No generic method 'Where' on type 'System.Linq.Queryable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.

I’m using LINQPad v4.42.01. The application sample is compiled vs .NET Framework 4 Client Profile.

The OriginalDepth property is of type double?.

Why is my query not working in LINQPad / why is it working in my application?

What can I do to fix the LINQPad query?

UPDATE

If I copy and paste my application code, including the definition of the dummy Borehole class and the creation of the dummy data list, into LINQPad, it works fine. Thus the issue is not that LINQPad rejects a query format that works in an application.

The question becomes: Why can I use g.Count(p => p.OriginalDepth == null) on a List<Borehole> object, but when I do the same query on the SQLite table accessed by LINQPad, I get InvalidOperationException as described above?

UPDATE 2

It doesn’t matter what the predicate for the g.count part of the query is. The following results in the same error, when executed against the SQLite database table:

var lq2 = from p in Boreholes
          group p by p.CostCenter into g
          select new { NullDepthCount = g.Count(p => true )}; 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:03:43+00:00Added an answer on June 7, 2026 at 7:03 pm

    Not every Linq provider is going to support every feature, so presumably you have hit on one here that the IQ provider does not support.

    If the size of the table is small (and sqlite databases usually are) then you can do

    var lq = from p in Boreholes.ToList()
          group p by p.CostCenter into g
          select new {  CostCenter = g.Key, 
                        AverageDepth = g.Average(p => p.OriginalDepth),
                        NullDepthCount = g.Count(p => p.OriginalDepth == null) };
    

    Obviously this loads the whole of the boreholes table into memory and hence the query is now a Linq To objects query which then works.

    Update.

    It would also appear that simply replacing

       NullDepthCount = g.Count(p => p.OriginalDepth == null)
    

    in your original query which

       NullDepthCount = g.Where(p => p.OriginalDepth == null).Count() 
    

    will work which means you don’t need to bring the data into memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following LINQ query: var queryGroups = (from p in db.cl_contact_event select
I have this following IEnumerable LINQ query: var query = from p in Enumerable.Range(2,
I have the following XML LINQ query from my XDocument. var totals = (from
I have the following Nhibernate LINQ query: var query = from c in session.Query<Customer>()
I have the following Linq query: List<MonthlySales> monthlySales = (from sale in Sales group
I have the following linq query: var files = (from d in new DirectoryInfo(@c:\program
I have the following LINQ query: var allocations = from ta in dc.TransactionAllocations where
In my code I have the following Linq Query: IQueryable<Data> charts = (from report
I have the following linq query: var allnews = from a in db.News where
I have the following linq query var ret = from u in MenuHeaders .Include(MenuHeaderItems.MenuItem)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.