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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:45:01+00:00 2026-06-16T01:45:01+00:00

I have a query over a single entity (with some navigation properties) and need

  • 0

I have a query over a single entity (with some navigation properties) and need to project them into a model for consumption by API clients. It looks basically like this:

repository.CreateQuery<Reviews>()
  .Where(/* criteria */)
  .Select(m => new
    {
      ID = m.ID,
      Reviewers = m.IsAnonymous 
        ? m.Reviewers.Take(1).Select(r => new { Name = "Anonymous" })
        : m.Reviewers.Select(r => new { Name = r.Name })
    })

LINQ to Entities fails to execute this at runtime. In the Visual Studio debugger, the exception message is “Specified method is not supported”. In LinqPad, the inner exception is “The nested query is not supported. Operation1=’Case’ Operations2=’Collect'”.

Any ideas how to work around this? I’d rather not force the query to execute to get the objects in memory because the point of this conditional query is to solve a performance issue, so as far as I can tell I really need to solve this within the scope of the L2E query.

Update: the projected types aren’t anonymous in my real application. I just used anonymous ones here because it was convenient to contrive the example. In similar fashion, the real queries involve a number of additional properties which mean a great deal more data coming from the mapped tables.

  • 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-16T01:45:03+00:00Added an answer on June 16, 2026 at 1:45 am

    You can use union to do what you want:

    var query1 = repository.CreateQuery<Reviews>()
                           .Where(/* criteria */);
    var queryAnonimous = query1.Where(m=>m.IsAnonymous)
                               .Select(m => new
                                            {
                                                ID = m.ID,
                                                Reviewers = m.Reviewers.Take(1).Select(r => new { Name = "Anonymous" })        
                                            })
    
    var queryNotAnonymous =  query1.Where(m=>!m.IsAnonymous)
                                   .Select(m => new
                                                {
                                                    ID = m.ID,
                                                    Reviewers = m.Reviewers.Select(r => new { Name = r.Name })
                                                })
    var unionQuery = queryAnonimous.union(queryNotAnonymous);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that I need to query over and over as fast
Yesterday I have been testing one single query for over hours and hours, but
I have a Delphi 2009 application that runs a query over a database using
I have a query: select event_type, department_name, effective_time, row_number() OVER (PARTITION BY event_type,department_name ORDER
I have an expensive query using the row_number over() functionality in SQL Server 2005.
I have a basic query that I run over and over at each 2
I have the following query: select top 100 eid, cid, id, position, ROW_NUMBER() over(order
I have a simple query over a table, which returns results like the following:
I've looked all over and have yet to find a single solution to address
I have Ienumerable<string> collection that I want to concatenate into a single string with

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.