{"id":1267,"date":"2022-01-18T19:17:10","date_gmt":"2022-01-18T09:17:10","guid":{"rendered":"https:\/\/moneystock.net\/wp_e\/?p=1267"},"modified":"2022-01-18T19:17:10","modified_gmt":"2022-01-18T09:17:10","slug":"ef-core-7-deadly-sin","status":"publish","type":"post","link":"https:\/\/moneystock.net\/wp_e\/2022\/01\/18\/ef-core-7-deadly-sin\/","title":{"rendered":"EF Core 7 deadly sin"},"content":{"rendered":"<p>Load testing tool<\/p>\n<p style=\"padding-left: 40px;\">Bombardier<br \/>\nhttps:\/\/github.com\/codesenberg\/bombardier<\/p>\n<p>&nbsp;<\/p>\n<p>EF Core 7 deadly sin<\/p>\n<ol>\n<li>Get only the rows that you need<\/li>\n<li><strong>Casting IQueryable -&gt; IEnumerable<\/strong>\n<ol>\n<li>use .Count() from IQueryable rather than IEnumerable, which will query all data and parsing all.<\/li>\n<\/ol>\n<\/li>\n<li><strong>Not using AsNoTracking<\/strong>\n<ol>\n<li>Can be faster 4x times.<\/li>\n<\/ol>\n<\/li>\n<li>Explicit joins\n<ol>\n<li>Select and map to the object directly rather than use &#8216;Include&#8217; and add everything.<\/li>\n<\/ol>\n<\/li>\n<li>Get only columns you need\n<ol>\n<li>Related to #4. Be explicit about what you select. This can be achieved by using projectto() in AutoMapper.<\/li>\n<\/ol>\n<\/li>\n<li>Pagination\n<ol>\n<li>Do paging in the query rather than in memory.<\/li>\n<\/ol>\n<\/li>\n<li>Non-cancellable queries\n<ol>\n<li>It will help recover quickly from a massive bad requests or a missive request attack.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>A few tips<\/p>\n<ol>\n<li>Utilize DbContextPool\n<ol>\n<li>This helps 1) reduce a connection start-up time 2) recycle unused SQL connections.<\/li>\n<\/ol>\n<\/li>\n<li>Bulk processing in chunks\n<ol>\n<li>e.g. foreach(var x in List.Chunk(count))<\/li>\n<\/ol>\n<\/li>\n<li>TagWith\n<ol>\n<li>e.g. TagWith(<span class=\"hljs-string\">&#8220;This is my spatial query!&#8221;<\/span>) help find it in log.<\/li>\n<\/ol>\n<\/li>\n<li>Sometimes raw SQL is good<\/li>\n<\/ol>\n<p>This article is a quick summary from the full video, https:\/\/www.youtube.com\/watch?v=x4TumMHiB6w<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Load testing tool Bombardier https:\/\/github.com\/codesenberg\/bombardier &nbsp; EF Core 7 deadly sin Get only the rows that you need Casting IQueryable -&gt; IEnumerable use .Count() from IQueryable rather than IEnumerable, which will query all data and parsing all. Not using AsNoTracking Can be faster 4x times. Explicit joins Select and map to the object directly rather&hellip; <a class=\"more-link\" href=\"https:\/\/moneystock.net\/wp_e\/2022\/01\/18\/ef-core-7-deadly-sin\/\">Continue reading <span class=\"screen-reader-text\">EF Core 7 deadly sin<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[122,548,582],"tags":[648],"class_list":["post-1267","post","type-post","status-publish","format-standard","hentry","category-asp-net-web-development","category-c","category-sql","tag-ef-core","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts\/1267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/comments?post=1267"}],"version-history":[{"count":1,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts\/1267\/revisions"}],"predecessor-version":[{"id":1272,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts\/1267\/revisions\/1272"}],"wp:attachment":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/media?parent=1267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/categories?post=1267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/tags?post=1267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}