i have used below linq query to join some table to get accurate data..
(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();
i have a small problem in CustomerDetail records i only want to get distinct records from the CustomerDetail based on the CustomerId….
CustomerDetail can have more than one records for the same CustomerId
please suggest how i can filter my query to get only distinct records from the CustomerDetail table
thanks,
LINQ provides the
Distinctmethod. However, it uses the default equality comparer by default, or optionally one you specified.I would recommend instead of using an anonymous type, define a class with the properties CustomerId and CustomerName, then override Equals.
and then