Sami C.
Sami C.

Oct 12, 2021

·
1 min read

EF Core — IQueryable inside foreach

Did you know that the following code will work:

The IQueryable<Entity> will attempt to load the entire query result into memory when enumerated.

I prefer to use the ToList()method to actually hit the database. In my opinion it’s a lot clearer than the example above.

Resolving query with .ToList

Make sure to read the following documentation about EF Core if you’re interested in performance!

Efficient Querying - EF Core

Querying efficiently is a vast subject, that covers subjects as wide-ranging as indexes, related entity loading…

docs.microsoft.com

Enjoy!

Entityframework Core
Csharp
Query
Database

--

--

More from Sami C.

Freelance Software Engineer

Recommended from Medium

Mybridge

Mybridge

in

Mybridge for Professionals

React.JS Top 10 Articles for the Past Month (v.July 2017)

Capt. Michael

Capt. Michael

How to integrate Stripe into Nuxt.js

Saumya Pandey

Saumya Pandey

in

Coding Blocks

What are Primitive Types and Special Values in javascript?

Jemusangi

Jemusangi

✪««鬼灭之刃 剧场版 无限列车篇 完整版本(2020-HD) Kimetsu no Yaiba: Mugen Ressha-Hen 完整版鬼灭之刃 剧场版 无限列车篇 Kimetsu no…

Adron Hall

Adron Hall

Dynamic Data Generation with JavaScript

InfallibleTechie

InfallibleTechie

Passing Custom Field Value to Chat Transcript object from Embedded Service Chat in Salesforce

Michael Nii Kwatei Quartey

Michael Nii Kwatei Quartey

JAVASCRIPT JOURNEY (EPISODE 3)

Laith Al-Samir

Laith Al-Samir

My Journey with AWS Amplify — Part 1 — Authentication

AWS Amplify Logo

AboutHelpTermsPrivacy


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Get unlimited access
Sami C.

Sami C.

139 Followers

Freelance Software Engineer

Help

Status

Writers

Blog

Careers

Privacy

Terms

About

Text to speech