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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:46:09+00:00 2026-06-18T01:46:09+00:00

I am building dynamic linq expressions which is working fine for a single entity.

  • 0

I am building dynamic linq expressions which is working fine for a single entity.
For example:
I have a class called Employee and empeduinfo

public class Employee
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public class EmpEduInfo
{
    public int Id { get; set; }
    public string Name  { get; set; }
    public int EmpId { get; set; }
}

I need to get all the the employees and empeduinfo class starts with “x”

I prepared expression for startswith(“x”)

var temp= entities.employees.Include("EmpEduInfo").Where(mydynamicexpression);

In this case it is filtering only parent table not on child.

I need to prepare generic expression so than i need to filter both parent and child objects dynamically.

Without using expression I know a solution:

var temp= (from ee in entities.Employee.Include("EmpEduInfo").Where(x => x.name.StartsWith("t"))                           
           where ee.EmpEduInfo.Where(x => x.name.StartsWith("t")).Count()>0                                
           select ee).ToList();

using expressions I am building generic expression to provide dynamic advance search rather than writing in each and every entity.

Here is my expression details

            // Get the method information for the String.StartsWith() method                
            MethodInfo mi = typeof(string).GetMethod("StartsWith", new Type[] { typeof(string) });
            // Build the parameter for the expression
            ParameterExpression  empparam= Expression.Parameter(typeof(employee), "ename");;
            // Build the member that was specified for the expression
            MemberExpression field = Expression.PropertyOrField(empparam, "name");
            // Call the String.StartsWith() method on the member
            MethodCallExpression startsWith = Expression.Call(field, mi, Expression.Constant("t"));                  
            var namelamda = Expression.Lambda<Func<employee, bool>>(startsWith, new ParameterExpression[] { empparam });
            var temp = entities.employees.Include("empedudetails").Where(namelamda).ToList();
  • 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-18T01:46:10+00:00Added an answer on June 18, 2026 at 1:46 am

    I was trying in EF 4.0 either we have write DB extentions for the same.

    Option is provided in EF 4.1

    http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/reading-related-data-with-the-entity-framework-in-an-asp-net-mvc-application

    Thanks.

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

Sidebar

Related Questions

I am building a dynamic view in a non-activity class, which is called by
hi i am building a dynamic web project in which the welcome page have
I am currently building a very dynamic table for a list application, which will
I'm building a query with the LINQ dynamic library so I don't know how
I have create a LINQ-to-SQL project in Visual Studio 2010 using Dynamic Data. In
I'm building a dynamic query that can have n of Where method calls and
I have been fiddling with dynamic LINQ for some time now, but I have
I m building dynamic lambda expression.I got the following operators working for this code
I know with dynamic linq you can construct expressions dynamically in the same way
I have been building a dynamic form in my Zend Framework application using Jquery

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.