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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:18:19+00:00 2026-05-20T02:18:19+00:00

I”m trying to build a generic cache layer. ICacheRepository Say I have the following:

  • 0

I”m trying to build a generic cache layer. ICacheRepository

Say I have the following:

public class Person
{
    public int PersonId { get; set; }
    public string Firstname { get; set; }
    public string Lastname { get; set; }
    public DateTime Added { get; set; }
}

And I have something like this:

list.Where(x => x.Firstname == "Syska");

Here I want to extract the above information, to see if the query supplied the “PersonId” which it did not, so I dont want to cache it.

But lets say I run a query like this:

list.Where(x => x.PersonId == 10);

Since PersonId is my key … I want to cache it. with the key like “Person_10” and I later can fetch it from the cache.

I know its possible to extract the information with Expression<Func<>> but there seems to be a big overhead of doing this (when running compile and extract the Constant values etc. and a bunch of cache to be sure to parse right)

Are there a framework for this? Or some smart/golden way of doing this ?

Updated information:

I’m using EF Code First CTP5.

When a entity is accessed through my Repository and queried only on some specific properties on my data class, I want to save it to the cache.

So when doing:

repository.SingleOrDefault(x => x.Email == "some@legel.mail");

And Email is my cache key for the “User” entity, I want my repository to cache it, because its being queried by “Email”.

Expression<Func<User, bool>> b;
b.Body // Here I can extract most information without compiling it, to fetch what its being quried for.

Its not that I can’t create a Expression parser, but as you says, there are many edge cases, where the existing SQL providers are way better. But thats not what I’m trying to do here.

I simple want to extract the right side of the BinaryExpression …. the best and fastest way. Since compiling every query is slow.

Even better I just want a cache layer for EF Code First.

  • 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-20T02:18:20+00:00Added an answer on May 20, 2026 at 2:18 am

    In order to do this, you actually want to process Expression<Func<bool, T>>. This contains the necessary metadata (in the form of expression objects) to allow you to inspect what was actually specified in the query. This is how ORMs like LINQ-to-SQL and the Entity Framework perform the translation from your strongly-typed query expressions into their respective query layers (LINQ-to-SQL straight to SQL, Entity Framework to EntitySQL, etc.).

    There are two ways for you to get at this information.

    1. Implement IQueryable<T>. This is the standard querying interface that all LINQ providers (such as those listed above) implement.
    2. Declare a function called Where on your type that takes Expression<Func<bool, T>> as its argument.

    Either way, you’ll get the expression. You can then do whatever you like to it, including compiling it and executing it as normal code.

    If you want to get started, head over to MSDN and take a peek. There’s a LOT of information, but it should be able to answer any questions you have. If not, you already know how to ask one here!

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

Sidebar

Related Questions

No related questions found

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.