Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am working on filtering a list using LINQ and came across a strange problem.

The code looks as follows:

filteredUsers = users.Where(x => x.ResourceTypeUserVms
        .Any(x => x.ResourceUserVms
        .Any(x => x.MetaData.ToLower().Contains(value))))
        .ToList();

        filteredUsers = filteredUsers
        .Select(x =>
        {
            x.ResourceTypeUserVms = x.ResourceTypeUserVms.Select(y =>
            {
                y.ResourceUserVms = y.ResourceUserVms.Where(s => s.MetaData.ToLower().Contains(value)).ToList();

                return y;
            }).ToList();
            x.ResourceTypeUserVms = x.ResourceTypeUserVms.Where(z => z.ResourceUserVms.Count() > 0).ToList();
            return x;
        }).ToList();

The users list contains the original data and the filteredUsers should only contain the filtered data. However, when I clear the filter (that means the original data should be displayed again), the users list seems to be manipulated.

Can anyone explain how I get the users list to stay the same no matter what?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
666 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...