question

IDGO-6443 avatar image
0 Votes"
IDGO-6443 asked IDGO-6443 edited

Huge Memory Issue in Entity framework Load Method

  this.Context.TestPRepetitions.Where(tp => sampleCodes.Contains(tp.SampleCode))
                 .Include(tp => tp.ReportableResults)
                 .Load();
    
  this.Context.Recognitions.Where(rec => reportableResultIds.Contains(rec.ReportableResultId)).Load();

Recognitions Table has 6352014 Rows



@AgaveJoe this what the Actual Method Does...




sql-server-generaldotnet-csharpdotnet-entity-framework
image.png (28.4 KiB)
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

In regards to memory leakage, don't use one DbContext for all your work, create a context for each operation with a using statement. Concerning using Contains, is the column properly indexed? Have you used SQL-Server Profiler?

Also see the following post.


0 Votes 0 ·
IDGO-6443 avatar image IDGO-6443 karenpayneoregon ·

@karenpayneoregon : I need to stop Memory Issue in SearchSamples Method.

0 Votes 0 ·

Well that is a given, please answer my questions.

0 Votes 0 ·

Perhaps you don't need to copy so much data from the database to C#? What are you doing with the data that requires C#?

0 Votes 0 ·

@AgaveJoe : I need to stop Memory Issue in SearchSamples Method.

0 Votes 0 ·

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered JackJJun-MSFT commented

Don’t use Load(). It’s whole point is to load all the rows into memory, and uses lots of memory.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

What's the alternative solution for load looking at the above method

0 Votes 0 ·

Can I write a sql query for searchsample method

0 Votes 0 ·

@IDGO-6443, yes, you can write a sql query for searchsample method, but according to your code it will be a bit complexity. BTW, please refer to use Raw SQL Queries to replace using ADO.NET to query the database.


0 Votes 0 ·