I am comparing 2012 with DateTime's Year integer in LINQ, and the LINQ return row with Year = 2013. I am wondering what wrong have I done.
var accountBalance_query = from report in context.AccountBalances
where report.FiscalYear.Year == reportYear &&
report.CompanyCode == companyCode &&
report.AccountNo == accountNo &&
(subLedgerTypeCode == null) ? report.SubLedgerTypeCode == null : report.SubLedgerTypeCode == subLedgerTypeCode &&
(subLedgerName == null) ? report.SubLedgerName == null : report.SubLedgerName == subLedgerName &&
report.AccountCurrencyCode == transactionCurCode
select report;
var reportCnt = accountBalance_query.Count();
if (reportCnt > 1)
{
reason = "Find more than 1 account balance in database that match the following key. " +
" CompanyCode = " + companyCode +
" AccountNo = " + accountNo +
" SubLedgerTypeCode = " + subLedgerTypeCode +
" SubLedgerName " + subLedgerName +
" Year " + reportYear +
" CurrenyCode " + transactionCurCode;
return false;
}
Model.GeneralLedger.AccountBalance accountBalance;
if (reportCnt == 1)
{
accountBalance = accountBalance_query.First();
}