<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Ef-Core on Ravindra Devrani</title><link>https://ravindradevrani.com/tags/ef-core/</link><description>Recent content in Ef-Core on Ravindra Devrani</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 10 Feb 2026 16:05:18 +0530</lastBuildDate><atom:link href="https://ravindradevrani.com/tags/ef-core/index.xml" rel="self" type="application/rss+xml"/><item><title>Dotnet Core Identity With .NET CLI</title><link>https://ravindradevrani.com/posts/dotnet-core-identity-with-dotnet-cli/</link><pubDate>Tue, 10 Feb 2026 16:05:18 +0530</pubDate><guid>https://ravindradevrani.com/posts/dotnet-core-identity-with-dotnet-cli/</guid><description>&lt;p>&lt;code>Aspnet core identity&lt;/code> provides an UI to registration, login, manage users, password, external authentication (google, twitter, facebook etc). In simple words, We can say it is an authentication and authorization feature in just few lines of commands and code. It is a nice feature, if you don&amp;rsquo;t want to use other managed authentication providers like Azure Entra Id / Okta Auth0 etc.&lt;/p>
&lt;p>Visual studio provides an UI way to enable identity. Which is very straightforward, but using CLI can be a little bit tricky. It is not always the case you are using visual studio (specially if you are using mac or linux). I use linux also. That is the whole reason to write this article.&lt;/p></description></item><item><title>LeftJoin and RightJoin in Ef Core 10</title><link>https://ravindradevrani.com/posts/left-join-ef-core-10/</link><pubDate>Tue, 16 Dec 2025 09:40:05 +0530</pubDate><guid>https://ravindradevrani.com/posts/left-join-ef-core-10/</guid><description>&lt;p>Previously there was no simple solution for left or right join. We had to use &lt;code>DefaultIfEmpty&lt;/code> or &lt;code>GroupJoin&lt;/code> and &lt;code>SelectMany&lt;/code>.&lt;/p>
&lt;p>With &lt;code>DefaultIfEmpty()&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-cs" data-lang="cs">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">var&lt;/span> customerOrders = &lt;span style="color:#66d9ef">await&lt;/span> (
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">from&lt;/span> c &lt;span style="color:#66d9ef">in&lt;/span> ctx.Customers
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">join&lt;/span> o &lt;span style="color:#66d9ef">in&lt;/span> ctx.Orders &lt;span style="color:#66d9ef">on&lt;/span> c.CustomerId &lt;span style="color:#66d9ef">equals&lt;/span> o.CustomerId &lt;span style="color:#66d9ef">into&lt;/span> orders
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">from&lt;/span> o &lt;span style="color:#66d9ef">in&lt;/span> orders.DefaultIfEmpty()
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">select&lt;/span> &lt;span style="color:#66d9ef">new&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> c.CustomerId,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> c.CustomerName,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> OrderId = o == &lt;span style="color:#66d9ef">null&lt;/span> ? &lt;span style="color:#ae81ff">0&lt;/span> : o.OrderId
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>).ToListAsync();
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>I have used the way described above in most of my career. It was really hard to remember that syntax and I always struggled with that.&lt;/p></description></item><item><title>Lazy Loading and N+1 Query Problem in Entity framework Core</title><link>https://ravindradevrani.com/posts/lazy-loading-and-n-plus-one-query-problem-in-ef-core/</link><pubDate>Thu, 27 Nov 2025 15:34:26 +0530</pubDate><guid>https://ravindradevrani.com/posts/lazy-loading-and-n-plus-one-query-problem-in-ef-core/</guid><description>&lt;!-- raw HTML omitted -->
&lt;p>&lt;a href="https://github.com/rd003/DotnetPracticeDemos/tree/master/LazyLoadingExample">💻Source code&lt;/a>&lt;/p>
&lt;h2 id="lazy-loading">Lazy loading&lt;/h2>
&lt;p>You load related entities on demand rather loading at once. This approach is usually useful when you want to load related entities on a certain condition (otherwise always use eager loading).&lt;/p>
&lt;p>To enable lazy loading, you need to install this package: &lt;code>Microsoft.EntityFrameworkCore.Proxies&lt;/code>&lt;/p>
&lt;p>And do following changes in &lt;code>Program.cs&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-cs" data-lang="cs">&lt;span style="display:flex;">&lt;span>builder.Services.AddDbContext&amp;lt;AppDbContext&amp;gt;(o=&amp;gt;o.UseLazyLoadingProxies()
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>.UseSqlite(&lt;span style="color:#e6db74">&amp;#34;Data Source = mydb.db&amp;#34;&lt;/span>));
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Look at the example below:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-cs" data-lang="cs">&lt;span style="display:flex;">&lt;span>app.MapGet(&lt;span style="color:#e6db74">&amp;#34;/&amp;#34;&lt;/span>, &lt;span style="color:#66d9ef">async&lt;/span> (AppDbContext context) =&amp;gt; {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">foreach&lt;/span> (&lt;span style="color:#66d9ef">var&lt;/span> genre &lt;span style="color:#66d9ef">in&lt;/span> &lt;span style="color:#66d9ef">await&lt;/span> context.Genres.ToListAsync()) 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">foreach&lt;/span> (&lt;span style="color:#66d9ef">var&lt;/span> book &lt;span style="color:#66d9ef">in&lt;/span> genre.Books)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Console.WriteLine(&lt;span style="color:#e6db74">$&amp;#34;===&amp;gt; genre: {genre.Name}, Book: {book.Title}, Price : {book.Author}&amp;#34;&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">return&lt;/span> Results.Ok(&lt;span style="color:#e6db74">&amp;#34;Ok&amp;#34;&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>});
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>We are not loading &lt;code>books&lt;/code> with &lt;code>genres&lt;/code> at once. Rather we are loading books for each genres. Let&amp;rsquo;s take a look at &lt;code>logs of console&lt;/code>.&lt;/p></description></item><item><title>Database Firsts Approach In EF Core</title><link>https://ravindradevrani.com/posts/db-first-approach-ef-core/</link><pubDate>Mon, 24 Feb 2025 17:49:15 +0530</pubDate><guid>https://ravindradevrani.com/posts/db-first-approach-ef-core/</guid><description>&lt;!-- raw HTML omitted -->
&lt;p>I have used &lt;code>database first&lt;/code> approach in the .NET Framework 4.X. But It is the first time I am trying to use Db First approach in the .NET Core (I am using .net 9). Microsoft refers it &lt;a href="https://learn.microsoft.com/en-us/ef/core/managing-schemas/scaffolding/?tabs=dotnet-core-cli">&amp;lsquo;Scaffolding (Reverse Engineering)&amp;rsquo;&lt;/a>. Personally I prefer &lt;code>Dapper&lt;/code> for DB First approach. May be you have an existing database and you want to use it with ENTITY FRAMEWORK, then this approach might be helpful. I am playing around it and documenting it and sharing that journey with you. Let&amp;rsquo;s see what it offers.&lt;/p></description></item></channel></rss>