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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:53:29+00:00 2026-06-04T23:53:29+00:00

Here is a simple project based on a Poco class named Task : class

  • 0

Here is a simple project based on a Poco class named Task:

class Program
{
    static void Main(string[] args)
    {
        using (MyDbContext ctx = new MyDbContext())
        {
            // first query
            DateTime compareDate = DateTime.Now + TimeSpan.FromDays(3);
            var res = ctx.Tasks.Where(t => t.LastUpdate < compareDate).ToList();

            // second query
            res = ctx.Tasks.Where(t => t.ShouldUpdate).ToList();
        }
    }
}

public class MyDbContext : DbContext
{
    public DbSet<Task> Tasks { get; set; }
}

public class Task
{
    public int ID { get; set; }
    public DateTime LastUpdate { get; set; }
    public  bool ShouldUpdate
    {
        get
        {
            return LastUpdate < DateTime.Now + TimeSpan.FromDays(3);
        }
    }
}

What I want to do is to query the context dbset including in the where clause the ShouldUpdate derived property.

The “first query works fine” (I can’t write it in a single line but it doesn’t matter).

As you know, we get a NotSupportedException on the “second query”, with the following message:
The specified type member ‘ShouldUpdate’ is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

That’s right and I can understand why it happen, but I need to encapsulate the derived information inside the Task object so I can display the property in a grid or use it in every other place, without duplicating the logic behind it.

Is there a smart technique to do this?

NB: What is the technical name of the ShouldUplate property? derived? calculated? computed?

  • 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-04T23:53:31+00:00Added an answer on June 4, 2026 at 11:53 pm

    Finally i found THE solution..
    You can store the partial queries (Expressions) in static fileds and use them like this:

    class Program
    {
        static void Main(string[] args)
        {
            using (MyDbContext ctx = new MyDbContext())
            {
                res = ctx.Tasks.Where(Task.ShouldUpdateExpression).ToList();
            }
        }
    }
    
    public class MyDbContext : DbContext
    {
        public DbSet<Task> Tasks { get; set; }
    }
    
    public class Task
    {
        public int ID { get; set; }
        public DateTime LastUpdate { get; set; }
        public bool ShouldUpdate
        {
            get
            {
                return ShouldUpdateExpression.Compile()(this);
            }
        }
    
        public static Expression<Func<Task, bool>> ShouldUpdateExpression
        {
            get
            {
                return t => t.LastUpdate < EntityFunctions.AddDays(DateTime.Now, 3);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple java project (adapted from the example here ), which is
Rails newbie here struggling with a small project. I am creating a simple ship
Here by simple, I mean a class with non-virtual empty destructor or POD type.
Hi i've got here a simple program, but it's not working properly. When i
I'm using NInject with NInject.Web.Mvc. To start with, I've created a simple test project
Here's a dead-simple webpage that leaks memory in IE8 using jQuery (I detect memory
I am playing with a simple project based on Django framework. My IDE is
I'm creating a simple project tagging application using the Act_As_Taggable_On gem. Adding projects, and
I have a bare-bones sample project here: http://dl.dropbox.com/u/7834263/ExpandingCells.zip In this project, a UITableView has
I'm looking at Haacks article here - http://haacked.com/archive/2009/07/31/single-project-areas.aspx When I download the sample I

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.