How to create a dynamic linq query

advertisements

I am trying to find the best way to build a dynamic linq query and populate a list. The user will have about five different fields in which they can choose to filter on. Currently i have the following code:

   List<TBLPROMOTION> promotionInfo = null;

    bool active = true;
    int storeId = 1

            using (WSE webStoreContext = new WSE())
        {
            promotionInfo =
                webStoreContext.TBLPROMOTION.Include("TBLSTORE").Include("LKPROMOTIONTYPE")
                .Where("STORE_ID==" + storeId + " and IS_ACTIVE == " + active).ToList();
        }

However, this example errors out because it cannot read the fields referenced in the where clause. Not sure why just saw this example somewhere else and tried to emulate it. My question is does anyone have an example that will work for my situation?

Thanks in advance, Billy


You probably were thinking of Dynamic LINQ. It will allow you to construct queries dynamically.