0

I'm getting log of last logged users and getting rid of duplicate

var log = Database.GetCollection<LoggerMongoDocument>(Consts.MongoDb.LoggerCollection).AsQueryable()
                                                         .Where(d => d.Description == "OK")
                                                         .OrderByDescending(s => s.Date).ToList();
var Users = log.GroupBy(i => i.UserAuthName).Select(group => group.First());

Then I've searched collection in mongodb to find proper users using foreach

var ListOfActivity = new List<MongoCursor<UserAuth>>();
    foreach (var item in Users)
                {
                    ListOfActivity.Add(Database.GetCollection(Consts.MongoDb.UserAuth).FindAs<UserAuth>(Query.EQ("Email", item.UserAuthName))
                              .SetFields(f => f.Roles, f => f.Id, f => f.UserName, f => f.Email));
                }

After that I want to assign all users to a variable, but I can only assign one user using select

var accounts = ListOfActivity.First().Select(x => new AccountExtended
            {
                Id = x.Id,
                Email = x.Email,
                Roles = x.Roles,
                CreatedDate = x.CreatedDate,
                UserName = x.UserName,
            }); 

How can I assign all users to a variable accounts?

Son Truong
  • 13,661
  • 5
  • 32
  • 58
Tom Alwson
  • 47
  • 1
  • 5
  • List of unrelated statement: 1/. Log don't need to be ordered, order on the not duplicate list, it has less elements. not sure the `ToList()` is needed here. 2/. `ListOfActivity` is basically a `Users.Select(item=> )`, right? 3/. `Accounts`, whats that `First`? – Drag and Drop Aug 30 '18 at 09:24
  • From you title you could be looking for: [Enumerable.SelectMany](https://msdn.microsoft.com/fr-fr/library/bb534336(v=vs.110).aspx). [Exemple on SO](https://stackoverflow.com/questions/958949/difference-between-select-and-selectmany) – Drag and Drop Aug 30 '18 at 09:25
  • If you are using .First() then you want only first item. Remove it and you will get entire list – ManishM Sep 01 '18 at 10:56

0 Answers0