A variable posted by user from ui:"_author".
it can be one name or comma seperated more names.. first one is ok but I need to deal with second scenario
_author = "Erick";// thats ok
here is fine with single name,
if (!string.IsNullOrEmpty(_author))
{
allQueryable = allQueryable.Where(u => u.Authors.Contains(_author));
}
_author = "Erick,Jennifer,Patrick,..";//hmmm
what I tried for this case:
if (!string.IsNullOrEmpty(_author))
{
if (_author.Contains(','))
{
allQueryable = allQueryable.Where(u =>u.Authors.Intersect(_author.Split(',').ToArray()));
}
else
allQueryable = allQueryable.Where(u => u.Authors.Contains(_author));
}
Entity defination:
public class Book : EntityBase
{
public string Title { get; set; }
public string Publisher { get; set; }
public string Description { get; set; }
public string[] Authors { get; set; }
}
if(!string.IsNullOrEmpty(_author)). You've excluded the "!" at the start of your condition.