我已经使用下面的 linq 查询来加入一些表以获取准确的数据..
(from row in
(from c in DbContext.Customer
join cd in DbContext.CustomerDetails
on c.Customer_Id equals cd.CustomerDetail_CustomerId
join cp in DbContext.ProductPurchases
on cd.CustomerDetail_OrgID equals cp.ProductPurchase_OrgID
where cd.CustomerDetail_OrgId == OrganizationID --organization Id is common
&& c.Customer_Org_Id == OrganizationID
&& cp.ProductPurchase_OrgID == OrganizationID
orderby cd.CustomerDetail_CreatedDate descending
select new { c, cd, cp })
select new CustomerDTO
{
CustomerId = row.cpd.CustomerDetail_CustomerID,
CustomerName = row.c.Customer_LastName+", "+row.c.Customer_FirstName,
}).ToList();
我在 CustomerDetail 记录中有一个小问题我只想根据 CustomerId 从 CustomerDetail 中获取不同的记录......
CustomerDetail 可以有多个相同 CustomerId 的记录
请建议我如何过滤我的查询以仅从 CustomerDetail 表中获取不同的记录
谢谢,