User-1355965324 posted
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,
InvoiceDate= sales.InvoiceDate,
Customer = sales.Customer
});
return saleslist;
}