Our company is currently using Entity Framework Net Core 2.2 with Sql Server
Trying to find all Distinct customers who purchased a certain Product Input Parameter. When trying to do final select, it shows b lambda as Product. We need the Distinct Customers showing up last.
How the EF Linq query be written to get this for distinct Customers?
var taxAgencyDistinctList = db.Customer .SelectMany(b => b.Transactions) .SelectMany(b => b.Purchases) .Select(b => b.Product) .Where(b => b.BKProduct == ProductInput) .Select(b => b.).Distinct(); Equivalent SQL is easy:
select distinct c.customerName from dbo.customer customer inner join dbo.Transactions transaction on transaction.customerid = customer.customerid inner join dbo.Purchases purchases on purchases.PurchaseId = transaction.PurchaseId inner join dbo.Product product on transaction.ProductId = product.ProductId where tra.BKProduct = @ProductInput Company prefers method, where we Don't use Linq to Sql, if possible
Resources:
Filtering on Include in EF Core
Filtering On ThenInclude Three Nested Levels down
Net Core: Entity Framework ThenInclude with Projection Select