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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:20:14+00:00 2026-05-10T21:20:14+00:00

Consider the following line of code: private void DoThis() { int i = 5;

  • 0

Consider the following line of code:

private void DoThis() {     int i = 5;     var repo = new ReportsRepository<RptCriteriaHint>();      // This does NOT work     var query1 = repo.Find(x => x.CriteriaTypeID == i).ToList<RptCriteriaHint>();            // This DOES work     var query1 = repo.Find(x => x.CriteriaTypeID == 5).ToList<RptCriteriaHint>();     } 

So when I hardwire an actual number into the lambda function, it works fine. When I use a captured variable into the expression it comes back with the following error:

No mapping exists from object type ReportBuilder.Reporter+<>c__DisplayClass0 to a known managed provider native type.

Why? How can I fix it?

  • 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. 2026-05-10T21:20:15+00:00Added an answer on May 10, 2026 at 9:20 pm

    Technically, the correct way to fix this is for the framework that is accepting the expression tree from your lambda to evaluate the i reference; in other words, it’s a LINQ framework limitation for some specific framework. What it is currently trying to do is interpret the i as a member access on some type known to it (the provider) from the database. Because of the way lambda variable capture works, the i local variable is actually a field on a hidden class, the one with the funny name, that the provider doesn’t recognize.

    So, it’s a framework problem.

    If you really must get by, you could construct the expression manually, like this:

    ParameterExpression x = Expression.Parameter(typeof(RptCriteriaHint), 'x'); var query = repo.Find(     Expression.Lambda<Func<RptCriteriaHint,bool>>(         Expression.Equal(             Expression.MakeMemberAccess(                 x,                 typeof(RptCriteriaHint).GetProperty('CriteriaTypeID')),             Expression.Constant(i)),         x)).ToList(); 

    … but that’s just masochism.

    Your comment on this entry prompts me to explain further.

    Lambdas are convertible into one of two types: a delegate with the correct signature, or an Expression<TDelegate> of the correct signature. LINQ to external databases (as opposed to any kind of in-memory query) works using the second kind of conversion.

    The compiler converts lambda expressions into expression trees, roughly speaking, by:

    1. The syntax tree is parsed by the compiler – this happens for all code.
    2. The syntax tree is rewritten after taking into account variable capture. Capturing variables is just like in a normal delegate or lambda – so display classes get created, and captured locals get moved into them (this is the same behaviour as variable capture in C# 2.0 anonymous delegates).
    3. The new syntax tree is converted into a series of calls to the Expression class so that, at runtime, an object tree is created that faithfully represents the parsed text.

    LINQ to external data sources is supposed to take this expression tree and interpret it for its semantic content, and interpret symbolic expressions inside the tree as either referring to things specific to its context (e.g. columns in the DB), or immediate values to convert. Usually, System.Reflection is used to look for framework-specific attributes to guide this conversion.

    However, it looks like SubSonic is not properly treating symbolic references that it cannot find domain-specific correspondences for; rather than evaluating the symbolic references, it’s just punting. Thus, it’s a SubSonic problem.

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

Sidebar

Ask A Question

Stats

  • Questions 97k
  • Answers 97k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could have a look at building a socket pool… May 11, 2026 at 7:24 pm
  • Editorial Team
    Editorial Team added an answer Using RSA to encrypt a lot of data is not… May 11, 2026 at 7:24 pm
  • Editorial Team
    Editorial Team added an answer It has a Dictionary: Does VBA have Dictionary Structure? And… May 11, 2026 at 7:24 pm

Related Questions

Consider the following code: private static void WriteProcesses(StreamWriter sw, DateTime d) { sw.WriteLine(List of
Consider the console application below, featuring a method with a generic catch handler that
Consider the following line of code: things.Add(new Thing { ID = null, Name =
Consider the following ruby code test.rb: begin puts thisFunctionDoesNotExist x = 1+1 rescue Exception

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.