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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:35:32+00:00 2026-05-20T01:35:32+00:00

I know there’s a way to do this but I’ve been banging my head

  • 0

I know there’s a way to do this but I’ve been banging my head against a wall trying to figure it out. This works fine:

private GenericRecord CreateGeneric(GenericRecord g, Member m)
{
    g.Member = m;
    return g;
}

public IList<GenericRecord> ReportFromDatabase(DateTime startDate, DateTime endDate)
{
    List<GenericRecord> returnRecords = new List<GenericRecord>();

    returnRecords.AddRange(from r in pjRepository.Records
                           join m in memberRepository.Members on r.SID equals m.MemberId.ToString()
                           where r.TransactionDate >= startDate && r.TransactionDate <= endDate
                           select CreateGeneric((GenericRecord)r, m));

    return returnRecords;
}

But I know there’s a way to do it without the CreateGeneric function. How do I select a delegate function inline?

returnRecords.AddRange(from r in pjRepository.Records
                       join m in memberRepository.Members on r.SID equals m.MemberId.ToString()
                       where r.TransactionDate >= startDate && r.TransactionDate <= endDate
                       select (delegate
                       {
                           GenericRecord g = (GenericRecord)r;
                           g.Member = m;
                           return g;
                       }));

That gives me this exception:

The type of the expression in the select clause is incorrect. Type inference failed in the call to 'Select'.

Edit: Another failed attempt

returnRecords.AddRange((from r in pjRepository.Records
                        join m in memberRepository.Members on r.SID equals m.MemberId.ToString()
                        where r.TransactionDate >= startDate && r.TransactionDate <= endDate
                        select new { r, m }).Select(x =>
                        {
                            GenericRecord g = (GenericRecord)x.r;
                            g.Member = x.m;
                            return g;
                        }));

This gives me:

A lambda expression with a statement body cannot be converted to an expression tree.

  • 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-20T01:35:32+00:00Added an answer on May 20, 2026 at 1:35 am

    Try:

    returnRecords.AddRange((from r in pjRepository.Records
                                join m in memberRepository.Members on r.SID equals m.MemberId.ToString()
                                where r.TransactionDate >= startDate && r.TransactionDate <= endDate
                                select new { r, m }).AsEnumerable().Select(x =>
                                {
                                    GenericRecord g = (GenericRecord)x.r;
                                    g.Member = x.m;
                                    return g;
                                }));
    

    The key different is that AsEnumerable() function. That takes an IQueryable and returns an IEnumerable, which behind the scenes forces the evaluation of the expression tree by the Linq provider. This prevents the Linq library from attempting to convert the second Select’s lambda to part of the expression tree (which it says it can’t); the second Select will instead perform its transformation on the actual im-memory collection produced by evaluating the IQueryable expression tree. Since you require the query to be evaluated before the statement ends anyway (so all the elements can be added to returnRecords), there should be no significant performance difference.

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

Sidebar

Related Questions

I know there are several topics out there about this, but none of them
I know there is alot of documentation out there on this stuff, but I
i know there's a few other posts like this, but i've been on this
I know there have been a few threads on this before, but I have
I know there have been quite a few posts on this but none seem
I know there is a lot on this topic but I can't get any
I know there are a lot of questions around on this subject, but I've
I know there are dozens of questions that ask about this error, but none
I know there are actually a number of questions similar to this one, but
I know there have been similar questions posted but I think the issue I'm

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.