Last post Sep 22, 2020 07:47 PM by mgebhard
Sep 22, 2020 06:42 PM|polachan|LINK
I am trying to give where clause with existing linq conditionally inside the if condition , But not working please help.
Here is my linq. if cusotmer id and product id should be given the where clause only if there is value is being passed .
public IEnumerable<SalesModel> GetSalesList(DateTime DateFrom, DateTime DateTo, int customerId,int productId)
IEnumerable<SalesModel> saleslist =
(from sales in Context.DailySales
join customer in Context.Customer on sales.CustomerID equals customer.CustomerID
where sales.InvoiceDate >= DateFrom && sales.InvoiceDate <= DateTo
if(customerId >0 , sales.CustomerId == customerId )
If(productId > 0 , sales.ProductID == productId)
select new SalesModel
Id = sales.id
ProductID = sales.ProductID,
Qty = sales.Qty,
Rate = sales.Rate,
Customer = sales.Customer
Sep 22, 2020 07:47 PM|mgebhard|LINK
The condition pattern is simply...
(customerId == 0 || sales.CustomerId == customerId)
... but your code does not follow openly published standards.
See the EF Core documentation to learn the syntax.