0
je suit requête SQL:complexe requête LINQ de SQL
SELECT Count(*) AS CountOfRecs FROM tblAccount INNER JOIN tblAccountOwner ON
tblAccount.[Creditor Registry ID] = tblAccountOwner.[Creditor Registry ID] AND
tblAccount.[Account No] = tblAccountOwner.[Account No] WHERE (tblAccountOwner.
[Account Owner Registry ID] = 731752693037116688) AND (tblAccount.[Account Type]
NOT IN ('CA00', 'CA01', 'CA03', 'CA04', 'CA02', 'PA00', 'PA01', 'PA02', 'PA03', 'PA04'))
AND (DATEDIFF(mm, tblAccount.[State Change Date], GETDATE()) <= 6
OR tblAccount.[State Change Date] IS NULL)
AND ((tblAccount.[Account Type] IN ('OD','CL00','PL00')) OR
(tblAccount.[Account Type] LIKE '%Overdra%'))
et je veux traduire en LINQ. J'ai créé LINQ mais il ne retourne pas le même nombre. SQL renvoie 2, LINQ renvoie 0.
public int OverDraftCount(long AccountOwnerRegistryId = 731752693037116688)
{
CreditRegistryContext context = new CreditRegistryContext();
string notAllowedAccountTypes = "CA00, CA01, CA03, CA04, CA02, PA00, PA01, PA02, PA03, PA04";
var subList = notAllowedAccountTypes.Split(',');
string AllowedAccountTypes = "OD,CL00,PL00";
var subList1 = AllowedAccountTypes.Split(',');
var query = from c in context.AccountOwners
.Where(p => p.CreditorRegistryId == p.Account.CreditRegistryId
&& p.AccountNo == p.Account.AccountNo
&& p.AccountOwnerRegistryId == AccountOwnerRegistryId
&& !subList.Contains(p.Account.AccountType)
&& (EntityFunctions.DiffMonths(
p.Account.StateChangeDate, DateTime.Now) < 6
|| p.Account.StateChangeDate == null
&& (subList1.Contains(p.Account.AccountType)
|| p.Account.AccountType.Contains("Overdra"))))
select c;
return query.Count();
}
Veuillez suggérer une solution.
On dirait que votre groupe de parenthèses est pas tout à fait la même chose. Aussi, est-ce supposé être '<6' ou' <6' pour 'DiffMonths'? – mellamokb
@mellamokb <6 et SQL est correct et le problème est avec LINQ parce que j'ai traduit ce SQL en LINQ – DotnetSparrow