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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:36:15+00:00 2026-05-14T06:36:15+00:00

I am trying to understand dynamic linq and expression trees. Very basically trying to

  • 0

I am trying to understand dynamic linq and expression trees. Very basically trying to do an equals supplying the column and value as strings. Here is what I have so far

 private IQueryable<tblTest> filterTest(string column, string value)
    {
        TestDataContext db = new TestDataContext();

        // The IQueryable data to query.
        IQueryable<tblTest> queryableData = db.tblTests.AsQueryable();

        // Compose the expression tree that represents the parameter to the predicate.
        ParameterExpression pe = Expression.Parameter(typeof(tblTest), "item");


        Expression left = Expression.Property(pe, column);
        Expression right = Expression.Constant(value);
        Expression e1 = Expression.Equal(left, right);

        MethodCallExpression whereCallExpression = Expression.Call(
            typeof(Queryable),
            "Where",
            new Type[] { queryableData.ElementType },
            queryableData.Expression,
            Expression.Lambda<Func<tblTest, bool>>(e1, new ParameterExpression[] { pe }));

        // Create an executable query from the expression tree.
        IQueryable<tblTest> results = queryableData.Provider.CreateQuery<tblTest>(whereCallExpression);

        return results;
    }

That works fine for columns in the DB. But fails for properties in my code eg

public partial class tblTest
{
    public string name_test
    {  get { return name; }  }
}

Giving an error cannot be that it cannot be converted into SQL. I have tried rewriting the property as a Expression<Func but with no luck, how can I convert simple properties so they can be used with linq in this dynamic way?

Many Thanks

  • 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-14T06:36:16+00:00Added an answer on May 14, 2026 at 6:36 am

    To use non-table properties, you’ll need to first materialize the query and use LINQ to objects. I don’t think you can query against both SQL and non-SQL properties at the same time for the reason that you state: non-SQL properties have no SQL translation. I suspect that if you do a ToList() before calling filterTest(), you’ll find that your code works just fine for both types of properties. Unfortunately, this probably isn’t what you want and, if your non-SQL property is derived from various SQL columns, you will need a way to generate an expression that matches the property definition instead.

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

Sidebar

Related Questions

I am trying to understand dynamic linq as used by Scott Guthrie in this
I am trying to understand c# dynamic. I have an ExpandoObject instance assigned to
I am trying to understand the process of dynamic linking, in detail. For the
I am trying understand ViewModels deeper and I have read many articles and blogs
I'm having some trouble trying to understand how to create a dynamic choice field
I'm using CakePHP 2.0 and I'm trying to understand how I can echo dynamic
So I am trying to have a dynamic tabs kind of thing using both
I'm trying to pass context into a dynamic expression that I evaluate every iteration
I was trying a sample program to understand the behavior of the dynamic GridView
I am trying to convert a Linq query that I have working in Linq

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.