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 7749325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:01:07+00:00 2026-06-01T11:01:07+00:00

I have a data access class that took me a while to get working.

  • 0

I have a data access class that took me a while to get working. For my app, I need to get different types of SQL Server tables where the WHERE clause only differs by the column name: some columns are read_time, others are ReadTime, and others are LastModifiedTime. So I thought I’d pass in the WHERE clause so I didn’t need to create a new method for 50 different tables. It looks simple, and it works, but I don’t understand something.

This method, with Expression<> as the parameter, works:

internal List<T> GetObjectsGreaterThanReadTime<T>(Expression<Func<T, bool>> whereClause) where T : class
{
    Table<T> table = this.Database.GetTable<T>();
    IEnumerable<T> objects = table.Where(whereClause);

    return objects.ToList();
}

Now, I was trying it this way (below) for a while, and it would just hang on the last line (ToList()). First, why would this compile? I mean, why can Expression and Func be used interchangeably as a parameter? Then, why does Expression work, and the Func version just hangs?

Note: The only difference between the above method and this one is the method parameter (Expression vs. Func).

internal List<T> GetObjectsGreaterThanReadTime<T>(Func<T, bool> whereClause) where T : class
{
    Table<T> table = this.Database.GetTable<T>();
    IEnumerable<T> objects = table.Where(whereClause);

    return objects.ToList();
}
  • 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-01T11:01:09+00:00Added an answer on June 1, 2026 at 11:01 am

    The Expression version calls Queryable.Where which generates an expression tree, which (when enumerated by ToList) is translated to sql and executed on the database server. Presumably, the database server will avail itself of an index based on the filter criteria, to avoid reading the whole table.

    The Func version calls Enumerable.Where which (when enumerated by ToList) loads the whole table (what you perceive as a hang) and then runs the filter criteria against the in-memory objects.

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

Sidebar

Related Questions

I have a class 'Data' that uses a getter to access some array. If
I have 2 classes. With the Generic Data Access class I can get the
I have a data access class that loads reference data. Each type of entity
So, I have an app that uses a SQL Server express db. I have
I have a data access library that has a few classes that all implement
I have a data access layer (DAL) that is written in ASP.NET 3.5 and
I have created a Data Access Layer using .NET. Everywhere that I update a
i have a data access layer that abstracts the rest of the application away
I have a data access layer that has separate classes for each table in
i have this method in my data access class and i have a unit

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.