我想知道Linq和SQL是否相等(意味着Linq會返回與SQL相同的結果集嗎?我沒有表中的數據,並且需要將SQL轉換爲LINQ請建議Linq查詢糾正
var excludeTypes = new[]
{
"CA00", "CA01", "CA03", "CA04", "CA02",
"PA00", "PA01", "PA02", "PA03", "PA04"
};
var accounts =
from account in context.Accounts
from owner in context.AccountOwners
from business in context.Businesses
from accountStatus in context.AccountStatuses
from legalStatus in context.LegalStatuses
where !excludeTypes.Contains(account.AccountType)
select new AccountsReport { Account = account };
ALTER VIEW [dbo].[vwRptBorrowerAccount]
AS
SELECT dbo.tblAccount.[Creditor Registry ID], dbo.tblAccount.[Account No], dbo.tblAccount.[Date Opened], dbo.tblAccount.[Account Status ID],
dbo.tblAccount.[Date First Reported], dbo.tblAccount.[Credit Limit], dbo.tblAccount.Balance, dbo.tblAccount.[Minimum Installment], dbo.tblAccount.[Account Type],
dbo.tblAccount.Term, dbo.tblAccount.Purpose, dbo.tblAccount.[Account Owner Notes], dbo.tblAccount.[Creditor Notes], dbo.tblAccount.Collateral,
dbo.tblAccount.[Collateral Value], dbo.tblAccount.[Legal Status ID], dbo.tblAccount.[Legal Status Date], dbo.tblAccount.LastUpdatedBy,
dbo.tblAccount.LastUpdated, dbo.tblAccount.[Unique ID], dbo.tblAccount.[Account Status Date], dbo.tblAccount.Payment, dbo.tblAccount.[Payment Date],
dbo.tblAccount.[Balance Date], dbo.tblAccount.[Term Frequency], dbo.tblAccount.[State Change Date],
dbo.fn_GetAccountTypeDescription(dbo.tblAccount.[Account Type]) AS [Account Type Description], dbo.tblBusiness.[Business Name] AS CreditorName,
dbo.tblBusiness.Address AS CreditorAddress, dbo.tblBusiness.City AS CreditorCity, dbo.tblBusiness.State AS CreditorState,
dbo.tblLegalStatus.[Legal Status Description] AS [Legal Status], dbo.tblAccountStatus.[Account Status Description] AS [Account Status],
dbo.tblAccountOwner.[Account Owner Registry ID]
FROM dbo.tblAccount INNER JOIN
dbo.tblAccountOwner ON dbo.tblAccount.[Creditor Registry ID] = dbo.tblAccountOwner.[Creditor Registry ID] AND
dbo.tblAccount.[Account No] = dbo.tblAccountOwner.[Account No] INNER JOIN
dbo.tblBusiness ON dbo.tblAccount.[Creditor Registry ID] = dbo.tblBusiness.[Registry ID] INNER JOIN
dbo.tblAccountStatus ON dbo.tblAccount.[Account Status ID] = dbo.tblAccountStatus.[Account Status ID] INNER JOIN
dbo.tblLegalStatus ON dbo.tblAccount.[Legal Status ID] = dbo.tblLegalStatus.[Legal Status ID]
WHERE (dbo.tblAccount.[Account Type] NOT IN ('CA00', 'CA01', 'CA03', 'CA04', 'CA02', 'PA00', 'PA01', 'PA02', 'PA03', 'PA04'))
您能否建議如何改正?我已經定義了實體之間的關係。 – DotnetSparrow 2011-05-11 17:02:34
如果我這樣寫:從帳戶的上下文。帳戶 來自業主帳戶。帳戶所有者 從業主業務。企業 – DotnetSparrow 2011-05-12 06:14:08
當然,這將工作。 – 2011-05-12 12:11:45