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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:20:05+00:00 2026-05-21T14:20:05+00:00

I would like to filter my entites depending on result of a function working

  • 0

I would like to filter my entites depending on result of a function working with their properties.

ie. I got entity like this:

public class Lorem
{
    public int A {get;set;}
    public int B {get;set;}
    public int C {get;set;}

    public double DoMath(int externalValue)
    {
        // real implementation is longer and more complex

        if(A==B) {
          // some calculations
          return 0.2;
        }
        if(B==C) {
          // some calculations
          return 0.9;
        }
        else return 0;
    }
}

Now I am querying entities and I would like to get only those with DoMath > 0.

// simplified scenario for example purpose
int someValue = 95;
// working with Entity Framework 4.1 Code First
var filtered = db.Lorems.Where(x=>x.DoMath(someValue) > 0);

I am getting this error:
LINQ to Entities does not recognize the method —–, and this method cannot be translated into a store expression.

Is it possible to make it work like this?
My skills in customizing lambda expressions and working with delegates is quite poor, so I would like to get some help.

Edit: Here is that ‘DoMath’ function real code (without comments, because they aren’t in english):

public double VypocitejPrislusnost(int value)
{
    if (A == B)
    {

        if (value <= C)
        {
            return 1;
        }
        if (value > D)
        {
            return 0;
        }
        else
        {
            double b = D - C;
            double tangens = Math.Tan(1 / b);

            double a = tangens * (D - value);

            return Math.Round(a, 2);
        }
    }

    if (C == D)
    {

        if (value >= B)
        {
            return 1;
        }
        if (value <= A)
        {
            return 0;
        }
        else
        {
            double b = B - A;
            double tangens = Math.Tan(1 / b);

            double a = tangens * (value - A);

            return Math.Round(a, 2);
        }
    }

    else
    {
        if (value >= B && value <= C)
        {
            return 1;
        }
        if (value <= A || value >= D)
        {
            return 0;
        }
        if (value > A && value < B)
        {
            double b = B - A;
            double tangens = Math.Tan(1 / b);

            double a = tangens * (value - A);

            return Math.Round(a, 2);
        }
        if (value > C && value < D)
        {
            double b = D - C;
            double tangens = Math.Tan(1 / b);

            double a = tangens * (D - value);

            return Math.Round(a, 2);
        }
        else
        {
            return 0;
        }
    }
}

It basically calculates y coordinate in triangle in different scenarios. I am using this to count how much the given value fits into a fuzzy set.

  • 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-21T14:20:05+00:00Added an answer on May 21, 2026 at 2:20 pm

    Entity Framework’s Where is expecting an Expression Tree, which will get converted to a t-sql statement. Unfortunately there is no translation from your DoMath method to t-sql, so you’d have to pull the results down into memory, and then call Where as you have it. The reason is that once your results are in memory, LINQ methods work on standard delegates, not expression trees, so there are no restrictions on what can be put in there

    To do this, just tack an AsEnumerable() in front of the Where—of course that will pull down your whole table into memory, so do this only if it’s reasonably small

    var filtered = db.Lorems.AsEnumerable().Where(x => x.DoMath(someValue) > 0);
    

    Of course if you can identify some basic circumstances under which your DoMath will not be greater than 0, you can filter those results out up front, using an expression tree. This will trim down the results coming from the database. You can then filter the rest in memory. I have no idea what your DoMath method does (you imply it’s more complicated than what’s listed in your question), but hypothetically something like this should work:

    var filtered = db.Lorems
                     .Where(x => x.A < 10 && x.B != x.C)
                     .AsEnumerable() 
                     .Where(x => x.DoMath(someValue) > 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to filter an array of items by using the map() function.
Is there a Bayesian filter library for .NET? I would like to setup a
I would like to clarify what is the proper way to filter user input
I would like to filter certain fields in my database which are Null, 0,
I have an IQueryable whose Entity Framework 4 objects I would like to project
I would like to filter a product collection to show only items that are
I am currently watching a video from 27C3 and I would like to filter
I have a list of Foos that I would like to filter according to
Would like to get a list of advantages and disadvantages of using Stored Procedures.
Would like to create a strong password in C++. Any suggestions? I assume it

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.