<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Albara fahed Alharissy </title>
    <description>The latest articles on DEV Community by Albara fahed Alharissy  (@albaradev).</description>
    <link>https://dev.to/albaradev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2227471%2Fdb645acf-239f-4626-91a6-2af4c153a63b.png</url>
      <title>DEV Community: Albara fahed Alharissy </title>
      <link>https://dev.to/albaradev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/albaradev"/>
    <language>en</language>
    <item>
      <title>Understanding Entity Framework Core — Part 1: Foundations</title>
      <dc:creator>Albara fahed Alharissy </dc:creator>
      <pubDate>Mon, 03 Aug 2026 18:13:37 +0000</pubDate>
      <link>https://dev.to/albaradev/understanding-entity-framework-core-part-1-foundations-35a7</link>
      <guid>https://dev.to/albaradev/understanding-entity-framework-core-part-1-foundations-35a7</guid>
      <description>&lt;p&gt;When I started learning Entity Framework Core, I thought the hardest part would be memorizing its APIs.&lt;/p&gt;

&lt;p&gt;I was wrong.&lt;/p&gt;

&lt;p&gt;The real challenge wasn't learning methods like &lt;code&gt;Where()&lt;/code&gt;, &lt;code&gt;Include()&lt;/code&gt;, or &lt;code&gt;SaveChanges()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It was understanding what actually happens behind the scenes.&lt;/p&gt;

&lt;p&gt;This article summarizes the first stage of my EF Core learning journey and covers the core concepts every .NET developer should understand before writing production code.&lt;/p&gt;




&lt;h2&gt;
  
  
  What You'll Learn
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Why EF Core exists&lt;/li&gt;
&lt;li&gt;What ORM is&lt;/li&gt;
&lt;li&gt;How EF Core translates LINQ into SQL&lt;/li&gt;
&lt;li&gt;Deferred Execution&lt;/li&gt;
&lt;li&gt;Change Tracker&lt;/li&gt;
&lt;li&gt;EF Core vs ADO.NET&lt;/li&gt;
&lt;li&gt;Database First vs Code First&lt;/li&gt;
&lt;li&gt;DbContext fundamentals&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Does EF Core Exist?
&lt;/h2&gt;

&lt;p&gt;Before Entity Framework Core, many .NET applications used &lt;strong&gt;ADO.NET&lt;/strong&gt; directly.&lt;/p&gt;

&lt;p&gt;ADO.NET gives developers full control over database access, but it also requires writing a lot of repetitive code.&lt;/p&gt;

&lt;p&gt;For almost every query, developers need to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open a database connection&lt;/li&gt;
&lt;li&gt;Write SQL manually&lt;/li&gt;
&lt;li&gt;Execute commands&lt;/li&gt;
&lt;li&gt;Read data from a &lt;code&gt;DataReader&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Map rows into C# objects&lt;/li&gt;
&lt;li&gt;Close the connection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This approach works well, but as applications grow, maintaining this code becomes increasingly difficult.&lt;/p&gt;

&lt;p&gt;Entity Framework Core reduces this boilerplate by allowing developers to work with C# objects while handling much of the mapping behind the scenes.&lt;/p&gt;




&lt;h2&gt;
  
  
  Understanding ORM
&lt;/h2&gt;

&lt;p&gt;ORM stands for &lt;strong&gt;Object-Relational Mapping&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of thinking only in terms of database tables and rows, we work with C# classes and objects.&lt;/p&gt;

&lt;p&gt;A simple mapping looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Database Table  →  C# Class
Database Row    →  Object
Database Column →  Property
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes applications easier to develop and maintain.&lt;/p&gt;

&lt;p&gt;However, an ORM does &lt;strong&gt;not&lt;/strong&gt; replace the need to understand databases.&lt;/p&gt;

&lt;p&gt;Knowing SQL, relationships, indexes, and query performance is still essential.&lt;/p&gt;




&lt;h2&gt;
  
  
  EF Core Is a Translator
&lt;/h2&gt;

&lt;p&gt;One misconception I had was believing EF Core somehow executes my C# code.&lt;/p&gt;

&lt;p&gt;It doesn't.&lt;/p&gt;

&lt;p&gt;Its primary responsibility is translating LINQ expressions into SQL.&lt;/p&gt;

&lt;p&gt;The database engine executes the SQL.&lt;/p&gt;

&lt;p&gt;EF Core simply translates the query and maps the returned data back into C# objects.&lt;/p&gt;

&lt;p&gt;A simplified pipeline looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LINQ
   │
   ▼
Expression Tree
   │
   ▼
EF Core
   │
   ▼
Database Provider
   │
   ▼
SQL
   │
   ▼
SQL Server
   │
   ▼
C# Objects
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Understanding this pipeline completely changed how I think about writing queries.&lt;/p&gt;




&lt;h2&gt;
  
  
  Deferred Execution
&lt;/h2&gt;

&lt;p&gt;Another important concept is &lt;strong&gt;Deferred Execution&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Consider this query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;students&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Students&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IsActive&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, nothing has been sent to the database.&lt;/p&gt;

&lt;p&gt;EF Core is only building the query.&lt;/p&gt;

&lt;p&gt;Execution happens only when the application actually requests the data.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="nf"&gt;ToList&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;FirstOrDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Knowing this helps avoid unnecessary database calls and write more efficient applications.&lt;/p&gt;




&lt;h2&gt;
  
  
  Change Tracker
&lt;/h2&gt;

&lt;p&gt;One of EF Core's most useful features is the &lt;strong&gt;Change Tracker&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of checking every object manually, EF Core tracks the state of each entity.&lt;/p&gt;

&lt;p&gt;Possible states include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Added&lt;/li&gt;
&lt;li&gt;Modified&lt;/li&gt;
&lt;li&gt;Deleted&lt;/li&gt;
&lt;li&gt;Unchanged&lt;/li&gt;
&lt;li&gt;Detached&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When &lt;code&gt;SaveChanges()&lt;/code&gt; is called, EF Core generates SQL only for tracked entities whose state has changed.&lt;/p&gt;

&lt;p&gt;This also explains why changes are sometimes not saved.&lt;/p&gt;

&lt;p&gt;If an entity isn't being tracked, EF Core has no way of knowing it has been modified.&lt;/p&gt;




&lt;h2&gt;
  
  
  EF Core vs ADO.NET
&lt;/h2&gt;

&lt;p&gt;Many beginners ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Should I stop using ADO.NET now that EF Core exists?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The answer is &lt;strong&gt;No&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Both tools solve different problems.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;EF Core&lt;/th&gt;
&lt;th&gt;ADO.NET&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Faster development&lt;/td&gt;
&lt;td&gt;Full SQL control&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Less repetitive code&lt;/td&gt;
&lt;td&gt;Minimal abstraction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Built-in Change Tracking&lt;/td&gt;
&lt;td&gt;Highly flexible&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Easier maintenance&lt;/td&gt;
&lt;td&gt;Useful for specialized scenarios&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The right choice depends on your application's requirements.&lt;/p&gt;




&lt;h2&gt;
  
  
  Database First or Code First?
&lt;/h2&gt;

&lt;p&gt;EF Core supports two development approaches.&lt;/p&gt;

&lt;h3&gt;
  
  
  Database First
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Start with an existing database&lt;/li&gt;
&lt;li&gt;Generate entity classes using Scaffolding&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Best for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Existing databases&lt;/li&gt;
&lt;li&gt;Legacy systems&lt;/li&gt;
&lt;li&gt;Enterprise applications&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Code First
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Start with C# classes&lt;/li&gt;
&lt;li&gt;Generate the database using Migrations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Best for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;New applications&lt;/li&gt;
&lt;li&gt;Greenfield projects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Neither approach is universally better.&lt;/p&gt;

&lt;p&gt;Choose the one that best fits your project.&lt;/p&gt;




&lt;h2&gt;
  
  
  Understanding DbContext
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;DbContext&lt;/code&gt; is the heart of EF Core.&lt;/p&gt;

&lt;p&gt;It is responsible for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Managing database connections&lt;/li&gt;
&lt;li&gt;Executing queries&lt;/li&gt;
&lt;li&gt;Tracking entities&lt;/li&gt;
&lt;li&gt;Saving changes&lt;/li&gt;
&lt;li&gt;Coordinating communication with the database&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Almost every EF Core operation starts with a &lt;code&gt;DbContext&lt;/code&gt; instance.&lt;/p&gt;




&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;p&gt;During this first stage of learning EF Core, I realized something important.&lt;/p&gt;

&lt;p&gt;Learning a framework isn't about memorizing APIs.&lt;/p&gt;

&lt;p&gt;It's about understanding:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why it exists&lt;/li&gt;
&lt;li&gt;Which problems it solves&lt;/li&gt;
&lt;li&gt;What happens behind the scenes&lt;/li&gt;
&lt;li&gt;When to use it—and when not to&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These concepts provide a much stronger foundation than simply learning syntax.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;In &lt;strong&gt;Part 2&lt;/strong&gt;, I'll explore how to query data with LINQ in EF Core, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Filtering&lt;/li&gt;
&lt;li&gt;Projection&lt;/li&gt;
&lt;li&gt;Aggregation&lt;/li&gt;
&lt;li&gt;Loading related data&lt;/li&gt;
&lt;li&gt;Joins&lt;/li&gt;
&lt;li&gt;Pagination&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're also learning .NET or Entity Framework Core, I'd love to hear about your experience.&lt;/p&gt;

&lt;p&gt;Feel free to leave a comment or connect with me.&lt;/p&gt;

&lt;p&gt;See you in &lt;strong&gt;Part 2&lt;/strong&gt; 🚀&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>efcore</category>
      <category>csharp</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
