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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:43:49+00:00 2026-05-26T17:43:49+00:00

I an tryin to join 4 tables within a query as per requirement. where

  • 0

I an tryin to join 4 tables within a query as per requirement. where as I wanted to add the conditions in where clause dynamically so, i could able to do this for 2 table query as of now. but this 4 table join is bit the complex join here. To extend the functionality i am using following code to add dynamic where clause :

public static class Extensions
    {
        public static IQueryable<T> AddEqualityCondition<T, V>(this IQueryable<T> queryable,
          string propertyName, V propertyValue)
        {
            ParameterExpression pe = Expression.Parameter(typeof(T), "p");

   IQueryable<T> x = queryable.Where<T>(Expression.Lambda<Func<T, bool>>(Expression.Equal(Expression.Property(pe, typeof(T).GetProperty(propertyName)), Expression.Constant(propertyValue, typeof(V)), false, typeof(T).GetMethod("op_Equality")), new ParameterExpression[] { pe }));
            return (x);
        }
    }

//
My code to add where conditions:

Query is:
 var agrs = (from agr in _dbContext.Agreements
                                 join amdv in _dbContext.AgreementMetaDataValues on agr.AgreementID equals amdv.AgreementID 
                                 join emd in _dbContext.EntityMetadatas on amdv.AttributeId equals emd.AttributeId
                                 join et in _dbContext.Entities on agr.EntityID equals et.EntityId
                                 select new  agr, amdv,emd });

//Add dynamically where conditions:
 agrs = agrs.AddEqualityCondition("?????", "A83C82C5-F9D6-4833-A234-EBB5D971280C");

This is working for 2 table join not for more than that. because within complex query it is generating the Annonymouse object. so
so what should i need to pass in place of “??????” marks…? typically need to pass the property name as”agr.AgreementId” but here it is throwing the expression as “Value Canot be Null : propertyName” in extension class.
Need more guidance for this …

  • 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-26T17:43:50+00:00Added an answer on May 26, 2026 at 5:43 pm

    I think you might want to consider something like (as an additional overload):

    public static IQueryable<T> AddEqualityCondition<T, V>(
        this IQueryable<T> queryable,
        Expression<Func<T, V>> selector, V propertyValue)
    {
        var lambda = Expression.Lambda<Func<T,bool>>(
           Expression.Equal(
               selector.Body,
               Expression.Constant(propertyValue, typeof(V)),
               false, typeof(T).GetMethod("op_Equality")),
            selector.Parameters);
        return queryable.Where(lambda);           
    }
    

    and using:

    agrs = agrs.AddEqualityCondition(x => x.agr.AgreementId, 
                 "A83C82C5-F9D6-4833-A234-EBB5D971280C");
    

    however! it is much easier to use just:

    agrs = agrs.Where(x => x.agr.AgreementId ==
                 "A83C82C5-F9D6-4833-A234-EBB5D971280C");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to join two tables; the purpose being able to search and
I have 2 tables within my EF4 project. They dont have a join. CustomerTable
I'm getting an error when trying to join against multiple tables in a query:
I am trying to join two tables like this... SELECT * FROM lists l
I'm trying to create a record within a join table from the action of
I'm trying to create a record within a join table from the action of
I'm trying to join multiple tables, but one of the tables has multiple records
I'm trying to LEFT JOIN two tables, to get a list of all rows
I have a 3 tables that I'm trying to join and get distinct results.
I'm trying to do a join on 2 tables in Zend, using the DbTable

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.