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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:26:48+00:00 2026-06-16T21:26:48+00:00

I work on project that use some dynamic linq query to an entities. i

  • 0

I work on project that use some dynamic linq query to an entities.
i have huge amount of case and to avoid code duplication i refactoring to a method.
But using method which isn’t in store expression will result to throw an exception.
One of solutions is to encapsulate method result into an expression which can be interpreted by linq to entitie query.

Consider that code :

parentExpression = x => x.child.Any(y=>IsGoodChild(y,childType, childSize));

private bool IsGoodChild(child c, int childType, int childSize){
     return c.type == childType && c.size == childSize;
}

“parentExpression ” is predicate of type “Parent” of my EF.
This code throw an exception, “IsGoodChild” method return a boolean and can’t be interpreted by linq to Entities.

So, i would like something like this :

parentExpression = x => x.child.AsQueryable().Any(IsGoodChild(childType, childSize));

private System.Linq.Expression.Expression<Func<child, bool>> IsGoodChild(int childType, int childSize){
     return  ????
}

So how can i do “IsGoodChild(…)” can work even if which not take x.child attribute ?
Thx for advance


Re,

I try something, when i write lambda directly in expression like this :

parentExpression = x => x.child.Any(y=>y.type == childType && y.size == childSize);

i used extract method from resharper and generate it this :

private Expression<Func<child,Boolean>> IsGoodChildFunctional(Int32 childType, Int32 childSize)
{
    return c => c.type == childType && c.size == childSize; 
}

But i also have .NET Framework Data Provider error 1025′ error …

  • 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-16T21:26:50+00:00Added an answer on June 16, 2026 at 9:26 pm

    Create a static generic method which will return an Expression. The Expression is built by using factory methods.

    public static Expression<Func<TTargetObject,Boolean>> IsGoodChildFunctional<TTargetObject>(Int32 childType, Int32 childSize)
    {
                var e = Expression.Parameter(typeof(TTargetObject), "e");
                var childTypeMember = Expression.MakeMemberAccess(e, typeof(TTargetObject).GetProperty("childType"));
                var childSizeMember = Expression.MakeMemberAccess(e, typeof(TTargetObject).GetProperty("childSize"));
                var  childTypeConstant = Expression.Constant(childType, childType.GetType());
                var  childSizeConstant = Expression.Constant(childSize, childSize.GetType());
                BinaryExpression b;
                BinaryExpression bBis;
                Expression<Func<TTargetObject, bool>> returnedExpression;
                b = Expression.Equal(childTypeMember , childTypeConstant );
                bBis2 = Expression.Equal(childSizeMember, c2);
                var resultExpression = Expression.AndAlso(b, bBis);
                returnedExpression = Expression.Lambda<Func<TTargetObject, bool>>(resultExpression , e);
                return returnedExpression;
    }
    

    It is called like this:

    var predicat = IsGoodChildFunctional<child>(childType, childSize);
    parentExpression = x => x.child.Any(predicat);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to use some dll files in my project that have a reference
We have some XSDs in our project that define types that use attributes, as
I'm working on an iOS project that has to work from iOS4. I have
I have a large c# project at work that controls a radar jammer. When
I was just told that I might have to work on a project where
I use some libraries that I don't want built as part of every project
I have a project ongoing at the moment that uses dynamic text blocks to
1) I have some static classes in my project that allocate variables within their
I have a Rails project that use the git to check the history. My
I work on a project that takes 2-3 minuts to compile. Usually when 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.