{"id":10046,"date":"2026-02-02T10:03:20","date_gmt":"2026-02-02T09:03:20","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=10046"},"modified":"2026-02-02T10:03:22","modified_gmt":"2026-02-02T09:03:22","slug":"linq-compare-year-month-or-year-week","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/linq-compare-year-month-or-year-week\/","title":{"rendered":"Linq Compare Year-Month or Year-Week"},"content":{"rendered":"\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"csharp\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">var begin = new DateOnly(DateTime.Now.Year, DateTime.Now.Month, 1);\nvar end = new DateOnly(DateTime.Now.Year, DateTime.Now.Month, 1);\n\nvar beginValue = begin.Year * 100 + begin.Month;\nvar endValue   = end.Year * 100 + end.Month;\n\nvar forecast = await GetRepository&lt;DmArticleForecast>(unitOfWork)\n    .AsQueryable()\n    .Where(x => elementGroupsToShow.Contains(x.ElementGroup))\n    .Where(x => (x.Year * 100 + x.Month) >= beginValue)\n    .Where(x => (x.Year * 100 + x.Month) &lt;= endValue)\n    .ToListAsync();\n    \n\/\/ or with two columns (using indexes)    \n.AsQueryable()    \n.Where(x =>\n    (x.Year > begin.Year || (x.Year == begin.Year &amp;&amp; x.Month >= begin.Month)) &amp;&amp;\n    (x.Year &lt; end.Year   || (x.Year == end.Year   &amp;&amp; x.Month &lt;= end.Month))\n)\n.ToListAsync();\n<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-10046","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/10046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=10046"}],"version-history":[{"count":1,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/10046\/revisions"}],"predecessor-version":[{"id":10047,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/10046\/revisions\/10047"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=10046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=10046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=10046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}