title: Convert SQL Statement into Linq expression
body: <p>I am quite new to linq and .net core. I am trying to calculate the next tax return date of a company as a part of my final year’s project.</p>
  <ol>
  <li>If there is a newly made company with no tax has been made yet (means no entry in the tax table), Then add 18 months in the company’s incorporated date.</li>
  <li>If the company has already paid tax, then pick the latest date TaxReturnDate from tax table and add 9 months into that to get the next TaxReturnDate.</li>
  </ol>
  <p>Thats what i have tried in SQL, now i am trying to convert this sql into Linq Query, I need some help to get the desired results.</p>
  <pre class="lang-sql prettyprint-override"><code>WITH
      cte_company (CompanyID, CompanyName, CompanyNumber, IncorporatedDate, TOTAL_YEARS) AS
          (SELECT
               CompanyID,
               CompanyName,
               CompanyNumber,
               IncorporatedDate,
               DATEDIFF(YEAR, IncorporatedDate, CURRENT_TIMESTAMP) AS TOTAL_YEARS
          FROM tbl_Company)
  SELECT
      cte_company.CompanyID,
      CompanyName,
      CompanyNumber,
      IncorporatedDate,
      TOTAL_YEARS,
      CASE
          WHEN TOTAL_YEARS &gt; 1 THEN (SELECT
              DATEADD(MONTH, 9, MAX(TaxReturnDate))
          FROM tbl_Tax
          WHERE cte_company.CompanyID = tbl_Tax.CompanyID)
          ELSE DATEADD(MONTH, 18, IncorporatedDate)
          END AS TaxDate
  FROM cte_company
  </code></pre>
  <p>Linq Query</p>
  <pre class="lang-cs prettyprint-override"><code>IEnumerable&lt;CompanyTaxInfo&gt; result = 
      from c in this.AcmeDB.tbl_Company
      let TotalYears = (DateTime.Now - c.IncorporatedDate).Value.Days / 365
      let taxReturnDate = this.AcmeDB.tbl_Tax.Max(tx =&gt; tx.TaxReturnDate).Value.AddMonths(9)
      select new CompanyTaxInfo
      {
          CompanyID = c.CompanyID,
          CompanyName=  c.CompanyName,
          CompanyNumber=  c.CompanyNumber,
          IncorporatedDate= c.IncorporatedDate,
          TotalYears = TotalYears,
          TaxDate = TotalYears &gt; 1 ? taxReturnDate :    c.IncorporatedDate.Value.AddMonths(21)
      };
  
  return result;
  </code></pre>
  <p>code is throwing DbArithmeticExpression arguments must have a numeric common type.' exception.</p>
  <p>Please help</p>