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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:17:38+00:00 2026-05-30T14:17:38+00:00

In my ASP.NET MVC3 application I have the following method that use EF entities

  • 0

In my ASP.NET MVC3 application I have the following method that use EF entities:

public IQueryable<Products> GetCreatedProducts(int year)
{
        return GetAllProducts().Where(m => Equals(DateUtilities.ExtractYear(m.ProductCreationDate), year));
}

ProductCreationDate is a field stored in the database as string “YYYYMMddhhmm”.

int DateUtilities.ExtractYear(string date) is a method that I created in order to get the year from the string. Similarly I use ExtractMonth and ExtractDay.

However when I execute my application it launches an NotSupported exception:

“LINQ to Entities does not recognize the method ‘Int32 ExtractYear(System.String)’ method, and this method cannot be translated into a store expression.”

By googling the problem I found out that it is a bug in LINQ to Entities Anybody knows a workaround?

  • 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-30T14:17:40+00:00Added an answer on May 30, 2026 at 2:17 pm

    You get the exception because you work with IQueryable. Entity Framework will try to translate the predicate in the where clause into SQL but EF doesn’t know how to translate your method.

    If you don’t want to (or can’t) change the database you still have a few options:

    1. Pull all rows to the client side and do the filtering on the client. You do this by changing from IQueryable to IEnumerable:

      return GetAllProducts()
        .AsEnumerable()
        .Where(m => Equals(DateUtilities.ExtractYear(m.ProductCreationDate), year))
        .AsQueryable();
      
    2. To be more efficient you can use your own SQL (this requires EF 4.1 and only avoid pulling all products to the client, not the scan on the server):

      return context
        .Products
        .SqlQuery("select * from Products where substring(ProductCreationDate, 1, 4) = '2012'")
        .AsQueryable();
      

      Note that I was lazy and hardcoded the SQL. You should probably parametrize it and make sure you avoid any SQL injection attacks.

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

Sidebar

Related Questions

I have a ASP.NET MVC3 application that handles time-consuming processes (copying a large file
I have the following WebGrid in my ASP.NET MVC3 test application. It displays a
I have a ASP.NET MVC3 application that gets a List of Coordinates from a
I am creating an ASP.NET MVC3 application using NHIBERNATE. I have a base class
This is about asp.net mvc3 web application. We have used Object cache to store
I have created a web application using ASP.NET MVC3 in Visual studio (no SQL
I used to have a standard ASP.NET MVC 3 application that was Ninject-wired via
I have an ASP.NET MVC3 in C# and Razor. The architecture of the application
Let's say I have the following structure in my ASP.NET MVC 3 application. Items
Folks, I have ASP.NET MVC 3 Application and I have the following JQuery script

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.