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

  • Home
  • SEARCH
  • 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 8411985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:33:48+00:00 2026-06-10T00:33:48+00:00

Using EntityFramework 4. I have an EntityCollection<SomeEntity> currentEntities with ~500k entities and a List<SomeEntity>

  • 0

Using EntityFramework 4. I have an EntityCollection<SomeEntity> currentEntities with ~500k entities and a List<SomeEntity> importedEntities also with ~500k records. I want to have the list of all records occuring in currentEntities which don’t exist in importedEntities.

Calling currentEntities.Select(x => x.ID).Except(importedEntities.Select(x => x.ID)) to get unique IDs of occurring records causes a System.OutOfMemoryException because it apparently loads all of the entities into the memory.

Calling currentEntities.Where(x => !importedEntities.Any(y => y.ID == x.ID)) fails with NotSupportedException (“Only primitive types (‘such as Int32, String, and Guid’) are supported in this context”).

currentEntities is on the SQL Server 2008 R2 database, while importedEntities are in memory.

Is this even possible in L2E ?

  • 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-10T00:33:50+00:00Added an answer on June 10, 2026 at 12:33 am

    Doing an except on two “large” lists of integers in memory is not a point. If I do Enumerable.Range(0, 500000).Except(Enumerable.Range(500, 500000)).Count() it returns 500 before I can say OutOfMemoryException. So I think reducing your problem to an except of integers should work for you:

    var newIds = importedEntities.Select(x => x.ID).ToArray()
                 .Except(currentEntities.Select(x => x.ID).ToArray()).ToArray();
    

    Thus, only integers will be loaded into memory, no entity objects.

    Now you can do:

    importedEntities.Where(x => newIds.Contains(x.ID))
    

    provided that newIds is not too long. What is too long? The linq statement produces an IN clause, which can easily contain a couple of thousands of items, but if it is longer than, say, 10,000 you probably should process the IDs in chunks.

    By the way (1). I’m assuming here that both lists are in different contexts, maybe even different databases. However, if they are in the same context, you might have success with:

    importedEntities.Where(x => !currentEntities.Select(y => y.ID)
                               .Any(id => id == x.ID))
    

    This produces a NOT EXISTS sql query. You may still run into an OutOfMemoryException though if there are “many” new items. If so, you could use a paging mechanism (Skip – Take) to process the new items in chunks.

    By the way (2), I swapped currentEntities and importedEntities, because I assume you are interested in the new imported items, please undo that if I’m wrong.

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

Sidebar

Related Questions

I am using EntityFramework to persist my entities. The problem I have is that
I am having trouble saving my entities to the database using EntityFramework. I have
I am using EntityFramework 4.1. I have the following model: public class User {
I'm using Entity Framework Code First v 4.3.0 I have a two entities with
I am using Entity Framework and DevExpress 10.5 XtraGrid. Imagine that we have entities
Background: We have a project with many modules. We're using EntityFramework 4.2 with FluentAPI
I have specified a couple of interfaces, which I am implementing as entities using
I have an object that I am trying to update using MVC(2), also using
We have moved our application away from using EntityFramework 4.2 and a couple of
I have a search repository for EntityFramework 4.0 using LinqKit with the following search

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.