我知道基本的LINQ,但我在几年内没有使用它。因此我忘记了LINQ。我无法将此SQL查询转换为LINQ。
SELECT
[CompanyName]
,[ContactPerson]
,[Address]
,[Email]
,[InActive]
,(Select SUM(isnull(CreditAmount,0) - isnull(DebitAmount,0)) FROM [dbo].[SupplierTransaction] where SupplierId = s.SupplierId) as Balance FROM [dbo].[Supplier] S
我尝试了这个,但它无法正常工作
from s in Suppliers
select new
{
s.SupplierId,
s.CompanyName,
s.ContactPerson,
s.Address,
s.Email,
s.InActive,
s.BranchId,
s.CreateDate,
s.CreatedBy,
s.UpdateDate,
s.UpdatedBy,
s.PhoneNumber,
Balance = (from v in SupplierTransactions
where v.SupplierId == s.SupplierId
select (v.Sum(v.CreditAmount-v.DebitAmount)))
}
答案 0 :(得分:2)
我没有测试过,但看起来应该是这样的:
picasso