<?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: Benziza</title>
    <description>The latest articles on DEV Community by Benziza (@benziza).</description>
    <link>https://dev.to/benziza</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%2F555697%2F267513ad-2cc3-491c-a667-2f0bde23889a.png</url>
      <title>DEV Community: Benziza</title>
      <link>https://dev.to/benziza</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/benziza"/>
    <language>en</language>
    <item>
      <title>Your endpoint returns 200 OK. It also ran 51 queries.</title>
      <dc:creator>Benziza</dc:creator>
      <pubDate>Thu, 20 Aug 2026 10:19:14 +0000</pubDate>
      <link>https://dev.to/benziza/your-endpoint-returns-200-ok-it-also-ran-51-queries-4m5d</link>
      <guid>https://dev.to/benziza/your-endpoint-returns-200-ok-it-also-ran-51-queries-4m5d</guid>
      <description>&lt;p&gt;A &lt;code&gt;200 OK&lt;/code&gt; doesn't tell you how much database work happened behind the response.&lt;/p&gt;

&lt;p&gt;An endpoint can return the exact same JSON, pass all its integration tests, and still quietly go from &lt;strong&gt;1 database query to 51&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That's the regression I wanted to catch.&lt;/p&gt;

&lt;h2&gt;
  
  
  QueryGuard.NET
&lt;/h2&gt;

&lt;p&gt;I built &lt;strong&gt;QueryGuard.NET&lt;/strong&gt; to make EF Core query behavior part of the test contract.&lt;/p&gt;

&lt;p&gt;It records EF Core commands executed inside a request or test, groups repeated SQL into fingerprints, and lets you enforce query budgets.&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="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;QueryGuardScope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"GET /api/companies"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;QueryGuardPolicy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"companies"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WithMaxOccurrencesPerFingerprint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/api/companies"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;QueryGuardAssert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Passes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CompleteAsync&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the sample project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;51 queries
same fingerprint executed 50x

Budget: 5
Result: FAIL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After fixing the query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;51 queries -&amp;gt; 1 query
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same response. Different database behavior.&lt;/p&gt;

&lt;p&gt;QueryGuard deliberately reports &lt;strong&gt;repeated-query candidates&lt;/strong&gt;, not "N+1 detected", because repeated SQL is evidence of an N+1 pattern, not proof.&lt;/p&gt;

&lt;p&gt;Parameter values aren't captured by default, and the current preview only observes EF Core.&lt;/p&gt;

&lt;p&gt;SQLite and PostgreSQL are integration-tested in CI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/Benziza/queryguard-dotnet" rel="noopener noreferrer"&gt;https://github.com/Benziza/queryguard-dotnet&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The project is MIT licensed and currently available as &lt;code&gt;0.1.0-preview.1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;One design question I'm especially interested in:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Would you rather enforce a total query count, or a per-fingerprint budget like “this query pattern may execute at most 5 times”?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Feedback from real EF Core codebases would be very useful.&lt;/p&gt;

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