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

  • Home
  • SEARCH
  • 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 7971975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:45:00+00:00 2026-06-04T07:45:00+00:00

I am having trouble with the following piece of code. Before I paste it,

  • 0

I am having trouble with the following piece of code. Before I paste it, Let me give a bit of history on what should happen.

I have a model containing 2 fields of interest at the moment, which is the name of the order the customer placed, and the date at which he/she placed it. A pre-calculated date will be used to query the dateplaced field (and should only query the dates , and not the time). The query counts the amount of duplicates that occur in the MondayOrder field, and groups them together. Now , when I exclude the where clause which should query the dates, the query runs great. However, The goal of this query is to count the amount of orders for the following week based on the date the order has been placed.

List<string> returnlist = new List<string>();
DateTime dt = getNextWeekMondaysDate().Date;
switch (day)
{
    case DayOfWeek.Monday: 
    {
        var CountOrders =
           from x in Data.EntityDB.Orders 
           group x by x.MondayOrder into m 
           let count = m.Count() 
           select new
           {
               MondayOrderItem = m.Key, Amount = count 
           };

        foreach (var item in CountOrders)
        {
            returnlist.Add(item.MondayOrderItem + " : " +
               item.Amount);
        }
    }
    break;

The getNextWeekMondaysDate() method has an overload which I can use, where if I supply it a date, it will get the following Monday’s date from the parameter given. The problem is though, LINQ does not accept queries such as the following:

var CountOrders =
    from x in Data.EntityDB.Orders 
    where getNextWeekMondaysDate(x.DatePlaced.Value).Date == dt
    group x by x.MondayOrder into m 
    let count = m.Count() 
    select new { MondayOrderItem = m.Key, Amount = count };

This is exactly what I must achieve. Is there any workaround for this situation?

UPDATE

Here is the exception I get when I try the 2nd query.

LINQ to Entities does not recognize the method ‘System.DateTime getNextWeekMondaysDate(System.DateTime)’ method, and this method cannot be translated into a store expression.

  • 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-04T07:45:01+00:00Added an answer on June 4, 2026 at 7:45 am

    You cannot do this directly, as user-defined method calls cannot be translated to SQL by the EF query provider. The provider recognizes a limited set of .NET methods that can be translated to SQL and also a number of canonical functions as well. Anything that cannot be expressed using these methods only is off-limits unless you write your own query provider (which is only theoretically an option).

    As a practical workaround, you can calculate an appropriate range for x.DatePlaced.Value in code before the query and then use specific DateTime values on the where clause.

    As an intellectual exercise, note that this method is recognized by the query provider and can be used as part of the expression. So this abomination should work too:

    var CountOrders =
        from x in Data.EntityDB.Orders 
        where EntityFunctions.AddDays(
            x.DatePlaced.Date.Value, 
            (9 - DateAndTime.DatePart(DateInterval.WeekDay, x.DatePlaced.Value)) % 7)
            .Date == dt
        group x by x.MondayOrder into m 
        let count = m.Count() 
        select new { MondayOrderItem = m.Key, Amount = count };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble with the following bit of code. //Send Creation email ListServDAO.sendCreateEmail(orgId,
Okay, I am having trouble with the following piece of code (in a header
I'm having trouble understanding the following bit of code that I was hoping would
I'm having trouble with the following code. What it should do is echo cats.php
I'm having a little trouble with making the following piece of code work. I
Hello I'm having trouble with the following piece of code: <h:selectOneMenu id=selectTipoAutorizacion value=#{autorizacion.codigoTipoAutorizacion} required=true>
Having trouble with the following segment of code. I'm getting a parameter count mismatch.
I am having trouble with the following SQL statement. I have had this issue
I am having some trouble with a piece of code below: Input: li is
I am new to jQuery and am having trouble following the documentation. I have

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.