Linq dynamically Add Where conditions

Cenk 956 Reputation points
2022-08-21T16:22:42.18+00:00

Hi,

I am getting values from various form inputs and trying to dynamically construct the where clause. I couldn't find a way to, unfortunately. Hope you can help.

Here is

public async Task<IEnumerable<Order>> GetOrdersForExport(int vendorId,string status, DateTime? startDateTime, DateTime? endDateTime)  
        {  
            var result = from order in _db.Orders  
                from orderDetail in _db.OrdersDetail on order.Id equals orderdetail.OrderId  
                from vendor in _db.Vendors on orderdetail.VendorId equals vendor.Id  
               select new {order, orderdetail, vendor} ;  
  
            if (vendorId != null)  
            {  
                  
            }  

            return await result;  
        }  

Here is the relations
233246-linq.png

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
697 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,302 questions
{count} votes