locked
Linq to search comma separated list RRS feed

  • Question

  • User1126057398 posted

    I was trying to get all records that satisfy filter condition something like below in linq:

    Select * from trIncentives where isdeleted=false and SupplierId in (1,2,3,4) and status in"1,2"

    In the below Linq, I am trying to add where condition:

    strSupp=input.Supplier;  //It can be null, can contain single value or multiple values sepated by comma.
    var inc = _trIncentiveRepository.GetAll()
       .WhereIf(!input.Filter.IsNullOrEmpty(),p => p.Name.Contains(input.Filter) )


    How can this be achieved in the above LINQ?

    Tuesday, December 11, 2018 5:07 PM

All replies

  • User1724605321 posted

    Hi geetasks ,

    You can try below code :

    strSupp = input.Supplier; //It can be null, can contain single value or multiple values sepated by comma.
    
    if (!input.Filter.IsNullOrEmpty())
    {
            string[] filter = strSupp.Split(',');
            var result = _trIncentiveRepository.GetAll().Where(p => filter.Contains(p.Name));
    }
    else
    {
            var result = _trIncentiveRepository.GetAll();
    }
    

    Best Regards,

    Nan Yu

    Wednesday, December 12, 2018 7:34 AM