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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:01:12+00:00 2026-05-27T13:01:12+00:00

In general, If I create an extension method that acts on an entity: public

  • 0

In general, If I create an extension method that acts on an entity:

public static MyEntity Foo(this MyEntity entity)
{
  // do something to the entity
}

One cannot directly use this in a projection from Linq-To-Entities such as follows:

var result = myContext.MyEntities.Select(x=> x.Foo());

Doing so yields an error such as:

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

I fully understand why this error occurs. My question is this: If I can provide an implementation of Foo that uses an expression tree, is there some way that I can add Foo to the operations that LINQ-to-entities understands? And if so – how?


Note: I can certainly convert it to a list like this:

var result = myContext.MyEntities.ToList().Select(x=> x.Foo());

And it doesn’t error. But I no longer have an IQueryable. I have an IEnumerable. If I were to use it like this:

var result = myContext.MyEntities.ToList().Select(x=> x.Foo()).First();

I would end up fetching ALL entities before taking the top one and discarding the rest – which would be horrible for performance.

  • 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-27T13:01:13+00:00Added an answer on May 27, 2026 at 1:01 pm

    Use LINQKit project, but instead of your method foo, You will be obliged to write expression tree which is equivalent.

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

Sidebar

Related Questions

i just create reading file feature. In general, what kind PHP class that usually
I am trying to develop some general purpose custom ValidationAttributes. The fact that one
how to create a general project only containing one folder in netbeans 6.9? In
I want to create a Visual Studio Extension. That extension, whenever ran by the
I have a general create function that submits a new user to the database
This is my test table: CREATE TABLE [General].[Test] ( [Name] NVARCHAR(20) NOT NULL, [SSN]
I have an Extension Method that verifies if the user is able to see
Is there a way in C# or .NET in general to create an attribute
I’m looking for some samples/tutorials/general pointers in doing either of the following. 1) Create
general question is i like to build logger class that writes to single log

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.