Need to a Linq Query without Memory Issue.

Indudhar Gowda 426 Reputation points
2022-05-08T09:20:33.737+00:00

Need to a Linq Query without Memory Issue.

I have 65 lakh Records in Recognitions Table.

  var mm = this.Context.Recognitions.Where(rec => reportableResultIds.Contains(rec.ReportableResultId)).Select(x => new  {x.ReportableResultId,x.Id,x.RecognitionCode,x.ReportableResult}).
                        SelectMany(y=>y.ReportableResult.Recognitions).ToList().

Above Code is also working but Memory Issue,

  this.Context.Recognitions.Where(rec => reportableResultIds.Contains(rec.ReportableResultId)).Load();  This Also is Working But Memory Issue.

Below is the SQL Trace, Just Copied Half.

SELECT 
    [Extent1].[RecognitionId] AS [RecognitionId], 
    [Extent1].[RecognitionCode] AS [RecognitionCode], 
    [Extent1].[ReportableResultId] AS [ReportableResultId], 
    [Extent1].[CreatedBy] AS [CreatedBy], 
    [Extent1].[CreatedOnUtc] AS [CreatedOnUtc], 
    [Extent1].[ModifiedBy] AS [ModifiedBy], 
    [Extent1].[ModifiedOnUtc] AS [ModifiedOnUtc]
    FROM [dbo].[Recognitions] AS [Extent1]
    WHERE [Extent1].[ReportableResultId] IN (cast('820b7266-0b2d-4c56-9c3b-49ba41b286ff' as uniqueidentifier), cast('8326719f-d020-40e0-b617-a648c159a9c4' as uniqueidentifier), cast('83c57eb4-f2f1-4cc8-9c95-ed5052fe236d' as uniqueidentifier), cast('83fb96e3-434c-437c-8ecb-cf4b24ad5583' as uniqueidentifier), cast('841c286d-9f3b-414f-9136-11ee6b8faf34' as uniqueidentifier), cast('84a06b41-7abd-4cd1-a0c5-34a3675a65f1' as uniqueidentifier), cast('8582ad47-aaac-4f54-bd6f-be207f2623ab' as uniqueidentifier), cast('86339529-9f09-4ce9-a410-508fb2205af5' as uniqueidentifier), cast('868d935f-e323-425c-b740-607888ca50a6' as uniqueidentifier), cast('86ecd85d-5e59-4f2d-8010-a1e92cf61a03' as uniqueidentifier), cast('86f807d4-9174-4053-ac16-9f138b1b38c2' as uniqueidentifier), cast('8889e5b6-c3ed-42e1-9c84-52b3014d0e13' as uniqueidentifier), cast('888c08aa-ad60-41ad-ae59-3aceff955ede' as uniqueidentifier), cast('8a7be95c-614c-47ca-a086-12f41cf6b6ca' as uniqueidentifier), cast('8b4b6df4-0230-4d52-9357-7d6a0f072d44' as uniqueidentifier), cast('8c4f0bea-30f2-4e74-9f10-1efa0c58915c' as uniqueidentifier), cast('8e2673ca-543f-4e47-8bd0-1fa95d66ad1b' as uniqueidentifier), cast('8effeb46-076d-43ea-a391-1d578aef384f' as uniqueidentifier), cast('902f14b1-b72e-4eb6-9375-edf27580d4e3' as uniqueidentifier), cast('909f7b24-1056-4ed0-ae63-bb664ed1132e' as uniqueidentifier), cast('910e6bc6-e77e-4866-84c3-de66da9a92e2' as uniqueidentifier), cast('91c3b078-9cf7-4cd2-951a-3f5549d3a1a7' as uniqueidentifier), cast('939c81cf-1d25-47bd-9f66-be2c3f532871' as uniqueidentifier), cast('93a324c1-19a0-4526-87e5-51c10fdc392a' as uniqueidentifier), cast('943a2739-ed6d-45e3-bb0f-198e25827293' as uniqueidentifier), cast('94465e47-b813-42f9-8434-4042ab59cc3d' as uniqueidentifier), cast('94cb2936-655a-42f5-be24-e9f2291a072b' as uniqueidentifier), cast('9513c481-3290-4bff-8c7d-d3802fd8b63f' as uniqueidentifier), cast('95b663be-a006-438c-a33b-d48e0ce718e9' as uniqueidentifier), cast('95b9a78d-e1e3-4a93-b2ab-95a2e67cb425' as uniqueidentifier), cast('963ed5d9-a652-427a-b45a-fa8b6ff975c5' as uniqueidentifier), cast('966ab479-d292-4d2f-a6df-39eb803cc6fa' as uniqueidentifier), cast('96fa26d0-c002-4d31-bc7a-964415a5f222' as uniqueidentifier), cast('976c2b31-ca58-492c-9f20-f66cd430631c' as uniqueidentifier), cast('97734294-eca5-4378-9c23-6fa2828c14a2' as uniqueidentifier), cast('97a7cd52-ed36-4a3b-8657-02016c147157' as uniqueidentifier), cast('97b6af41-ff5d-46a6-b968-e26f58e2350b' as uniqueidentifier), cast('98102d13-336c-4161-8204-d8af42c9ab4e' as uniqueidentifier), cast('9876ebab-112b-49b2-ba78-3563863488c8' as uniqueidentifier), cast('98ad9bb0-22d2-423c-9389-bafe77de2a9e' as uniqueidentifier), cast('99245eea-58fb-4b24-b7f6-8827d4732401' as uniqueidentifier), cast('99cdffbe-75bd-4ad2-aff9-7c0ebc2f965f' as uniqueidentifier), cast('9aacd9a9-52d7-496d-881f-4599abc17209' as uniqueidentifier), 

Requirement : Need Linq Query which does not impact Memory Issue.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,639 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,343 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,641 questions
{count} votes