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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:56:28+00:00 2026-05-23T05:56:28+00:00

Following my previous question: Lambda expression to access a property of an object that

  • 0

Following my previous question:

Lambda expression to access a property of an object that is property of another object in c#

I have now another problem:

var param = Expression.Parameter(typeof(GAcordos.Models.Contratos), "x");
                    var body = Expression.Equal(Expression.PropertyOrField(Expression.PropertyOrField(param, propName[0]), columnName.ToString()), fixedItem, false, Type.GetType("GAcordos.Helpers.Comparators").GetMethod(oper, new Type[] { propType, propType }));
                    var lambda = Expression.Lambda<Func<GAcordos.Models.Contratos, bool>>(body, param);

                    contratosList = contratosList.Where(lambda).AsQueryable();

When passing the lambda to the Expression.Where method it doesn’t execute the replacement method I gave to the Equal Expression, and executes the standard Equal comparison.

If I compile lambda:

contratosList = contratosList.Where(lambda.Compile()).AsQueryable();

it throws an exception Object reference not set to an instance of an object. later in the View, with the following stacktrace:

 at lambda_method(Closure , Contratos )
 at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
 at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
 at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext()
 at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
 at lambda_method(Closure )
 at System.Linq.EnumerableExecutor`1.Execute()
 at System.Linq.EnumerableQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
 at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
 at MvcContrib.Pagination.LazyPagination`1.TryExecuteQuery() in C:\Users\daniel.almeida\Downloads\MVCContrib.source\src\MVCContrib\Pagination\LazyPagination.cs:line 62
 at MvcContrib.Pagination.LazyPagination`1.get_TotalItems() in C:\Users\daniel.almeida\Downloads\MVCContrib.source\src\MVCContrib\Pagination\LazyPagination.cs:line 85
 at MvcContrib.UI.Pager.Pager.ToHtmlString() in C:\Users\daniel.almeida\Downloads\MVCContrib.source\src\MVCContrib\UI\Pager\Pager.cs:line 130
 at MvcContrib.UI.Pager.Pager.ToString() in C:\Users\daniel.almeida\Downloads\MVCContrib.source\src\MVCContrib\UI\Pager\Pager.cs:line 125
 at ASP._Page_Views_Shared_Pager_cshtml.Execute() in c:\inetpub\wwwroot\Empresas\Proactivos\GAcordos\GAcordos\Views\Shared\Pager.cshtml:line 4
 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
 at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
 at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
 at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
 at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
 at System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper htmlHelper, String partialViewName, Object model)
 at ASP._Page_Views_Contratos_Index_cshtml.Execute() in c:\inetpub\wwwroot\Empresas\Proactivos\GAcordos\GAcordos\Views\Contratos\Index.cshtml:line 29
 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
 at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
 at System.Web.WebPages.StartPage.RunPage()
 at System.Web.WebPages.StartPage.ExecutePageHierarchy()
 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
 at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
 at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
 at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
 at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)

What could be wrong?

  • 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-23T05:56:29+00:00Added an answer on May 23, 2026 at 5:56 am

    The problem was not the lambda expressions. It was caused when loading info from the dababase, it was querying the database for the related tables when iterating the result of the query for the main table.

    This was solved adding MultipleActiveResultSets=true to the provider part of the connection string.
    See the solution for:

    There is already an open DataReader associated with this Command which must be closed first.

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

Sidebar

Related Questions

following this previous question Malloc Memory Corruption in C , now i have another
Following on from my previous question [link text][1] , I have a new problem.
Following on from my previous question, Python time to age , I have now
As in my previous question I have the following problem. I have a matrix
In a comment on a previous question, someone said that the following sql statement
I have the following lambda expression: IEnumerable<Order> query = _ordersRepository.GetAllByFilter( o => o.OrderStatus.OrderByDescending(os =>
Following my previous question . I have a table named activity with 2 columns:
Following my previous question , in which I think I've narrowed my problem down
This is based on my previous question . I have the following table Table1
Following my previous question (I assume that 64-bit compiler uses only SSE instructions for

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.