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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:18:02+00:00 2026-05-26T23:18:02+00:00

I want to query my item in table Items, where the last update of

  • 0

I want to query my item in table Items, where the last update of each item must be less than 91 days old (from last update till now) and the quantity > 0.
This is my code in the Model:

public IList<Item> GetAllProducts()
{
 var ien_item = from i in this.DataContext.Items  
 orderby i.LastUpdated descending
 select i;
 return ien_item.ToList().Where(
                 s =>
                 HelperClasses.HelperClass.IsLastUpdate(s.LastUpdated.Value) == true 
                 && 
                 (s => s.Quantity) > 0
                 )
                 .ToList();

}

Anyone can solve it? Thanks.

  • 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-05-26T23:18:02+00:00Added an answer on May 26, 2026 at 11:18 pm

    We don’t really know what’s not working here. EDIT: Merlyn spotted it; your lambda syntax is messed up. There’s more to do here though.

    However, I’d have thought you’d want this:

    public IList<Item> GetAllProducts()
    {
         var lastUpdateLimit = DateTime.UtcNow.Date.AddDays(-91);
         var query = from item in DataContext.Items
                     where item.Quantity > 0 && item.LastUpdated >= lastUpdateLimit
                     orderby item.LastUpdated descending
                     select item;
         return query.ToList();
    }
    

    Note that this is able to do all the querying at the database side instead of fetching all the items and filtering at the client side. It does assume that HelperClasses.HelperClass.IsLastUpdate is simple though, and basically equivalent to the filter I’ve got above.

    (One additional point to note is that by evaluating UtcNow.Date once, the result will be consistent for all items – whereas if your code evaluates “today” on every call to IsLastUpdate, some values in the query may end up being filtered against a different date to other values, due to time progressing while the query is evaluating.)

    EDIT: If you really need to use HelperClasses.HelperClass.IsLastUpdate then I’d suggest:

    public IList<Item> GetAllProducts()
    {
         var query = from item in DataContext.Items
                     where item.Quantity > 0
                     orderby item.LastUpdated descending
                     select item;
         return query.AsEnumerable()
                     .Where(s => HelperClass.IsLastUpdate(s.LastUpdated.Value))
                     .ToList();
    }
    

    … then at least the quantity filter is performed at the database side, and you’re not creating a complete buffered list before you need to (note the single call to ToList).

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

Sidebar

Related Questions

I want to group results of query by the item id and count number
I'm accepting dates from a wicket form - now I want query my DAO
I want to query the server to see if the date is different than
I want to query the name of all columns of a table. I found
I want to query a table so that it´s ordered the following way: 1)
I want to query my database and get counts of the occurences of each
I want to add a column containing images in each cell of a table
I want to show most popular items of store on website Table 1 is
i want to run the same query ten times. INSERT INTO items VALUES ('item_name')
i want query a file xml with linq, i want get all descendat of

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.