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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:01:51+00:00 2026-05-13T17:01:51+00:00

I’ve been working around a problem I have when using LINQ to Entities when

  • 0

I’ve been working around a problem I have when using LINQ to Entities when using closures.

Apparently, L2E does not support closures. Meaning:

var users = from user in UserRepository.FindAll()
            select new UserDTO
            {
               UserId = user.UserId,
               Tickets = from ticket in TicketRepository.FindAll()
                         where ticket.User == user
                         select new TicketDTO
                         {
                           TicketId = ticket.TicketId
                         }
            };

(NOTE: The “where”-clause is where the problem exists. I am not allowed to compare an entity to another entity because they are not EF primitive types. Only things like Int32, Guid etc. is allowed.)

, is not valid because I cannot compare ‘ticket.User’ to ‘user’

This is simply an example of the problem I have, and I realize that I could compare on the Id, since this a primitive type, as opposed to a closure.

In reality my scenario is alot more complex than this, but this is the scenario I need to solve for now.

A work-around I found online is using a subquery. That DOES work, but for my scenario it’s not very effective.

Question:

Do any of you know if:

  1. Entity Framework 4 will support Closures in LINQ to Entities?
  2. There is a better solution to this problem than using sub-queries?
  3. Any additional knowledge you have on this topic will be greatly appreciated!
  • 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-13T17:01:51+00:00Added an answer on May 13, 2026 at 5:01 pm

    This is not a problem directly related to closures. The problem is (probably) that you are mixing Entity Framework entities and your data transfer objects. The LINQ provider tries to convert the expression tree of your query into SQL statements and fails because it cannot separate the data transfer objects from the entities and the database, of course, cannot deal with the data transfer objects, too.

    I suggest to make the separation much cleaner – at first fetch the data from the database using LINQ to Entity and maybe anonymous types if required, then switch to LINQ to Objects to construct data transfer objects from the retrieved data and all should be fine. Something like the following. (Just to note – I am (safely) assuming the repositories return IQueryable<T>s (else the whole stuff should not work at all).)

    var result = UserRepository
          .FindAll()
          .Select(user => new
             {
                UserId    = user.UserId,
                TicketIds = TicketRepository
                               .FindAll()
                               .Where(ticket => ticket.User.UserId == user.UserId)
                               .Select(ticket => ticket.TicketId)
             });
    

    Transforming this query result into data transfer objects is now straight forward. Note that the users are compared via the IDs because the Entity Framework does (not yet) support comparisons by reference.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Taking some knowledge from this previous question, I would do… May 13, 2026 at 8:47 pm
  • Editorial Team
    Editorial Team added an answer There are infinitely many possible answers. So I will give… May 13, 2026 at 8:47 pm
  • Editorial Team
    Editorial Team added an answer I made some tries, and I guess that building the… May 13, 2026 at 8:47 pm

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

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.