I have my code sample below.
List<string> userIds = userAppService.GetUserIds()
.Where(usr => usr.Status == "Active")
.Select(u => u.User_Id)
.ToList();
Now i would like loop through list of above UserId's and add the result to var variable.
foreach(string str in userIds)
{
var result = SLSDBContext.USER_HISTORY
.Where(i => i.UserId == str)
.Select(x => new
{
x.UserId,
x.LogCount,
x.IsRegistered
});
return this.Json(result)
}
The problem with above is i will not be able to access 'result' variale outside of foreach block.. If i am trying yo declare 'result' variable before foreach block i am not able to assign the type to it.
any better way to get the desired result ?
I tried using Any() operator in Linq but i am not able to get the desired result.
var result = SLSDBContext.USER_HISTORY
.Where(i => i.UserId.Contains(userIds))
.Select(x => new
{
x.UserId,
x.LogCount,
x.IsRegistered
});
Where(i => userIds.Contains(i.UserId)), notWhere(i => i.UserId.contains(userIds))