HI All,
I am new to Linq so I request for your help me in this issue.
so I have methods which return a list of the user as shown below
var usernames = getuser(userID.ToString());
getuser method as show below
public static List<string> GetUser(string id)
{
List<string> user1 = new List<string>();
if (!string.IsNullOrWhiteSpace(id))
{
getUser repository = new getUser();
user1 = repository.GetUserbyid(id);
repository.Dispose();
}
return user1;
}
so I am getting all the users using the string builder
foreach (var item in usernames)
{ sb.AppendLine("p.username.Contains("+ item.ToString().ToLower()+")" + "||"); }
the output of sb as shown below
{p.CreatedBy.Contains(011)||p.CreatedBy.Contains(009)||p.CreatedBy.Contains(0000000010)}
so I have a predicate as shown below
var predictate = PredicateBuilder.True<Getuserdeatils>();
so I have the query where it used for the different operation.so I have to changed only the predictate part of the query as shown below.
var query = (from sr in context.Getuser.AsExpandable().Where(predictate)
join wi in context.UserProfiles on sr.CreatedBy equals wi.UserName into list1
from l1 in list1.DefaultIfEmpty()
so in the above query i want predictate as following
predictate = predictate.And( p => p.username.Contains("010") ||p.username.Contains("011") || p.username.Contains("009"));
thanks in advance.
What I have tried:
I have tried as follwoing
foreach (var item in usernames)
{
predictate = predictate.And(p =>p.CreatedBy.Contains(item.ToString()));
}
and
predictate = predictate.And(p =>((bool.Parse(sb.ToString()))));