❔ ✅ may someone help me to rewrite this in linq?
var map = new Dictionary<string, List<NotificationModel>>();
foreach (var notification in confirmedNotifications)
{
var to = notification.To
.Except(new HashSet<string> { currentOperator.Name })
.ToList();
if (!to.Any()) continue;
foreach (var user in to)
{
if (map.ContainsKey(user))
map[user].Add(notification);
else
map[user] = new List<NotificationModel> { notification };
}
}
var map = new Dictionary<string, List<NotificationModel>>();
foreach (var notification in confirmedNotifications)
{
var to = notification.To
.Except(new HashSet<string> { currentOperator.Name })
.ToList();
if (!to.Any()) continue;
foreach (var user in to)
{
if (map.ContainsKey(user))
map[user].Add(notification);
else
map[user] = new List<NotificationModel> { notification };
}
}
var test = confirmedNotifications
.Where(notification => notification.To
.Except(new HashSet<string> { currentOperator.Name })
.Any());
var test = confirmedNotifications
.Where(notification => notification.To
.Except(new HashSet<string> { currentOperator.Name })
.Any());
3 Replies
var res = confirmedNotifications
.SelectMany(notification => notification.To, (notification, to) => (notification, to))
.Where(t => t.to != currentOperator.Name)
.ToLookup(t => t.to, t => t.notification);
var res = confirmedNotifications
.SelectMany(notification => notification.To, (notification, to) => (notification, to))
.Where(t => t.to != currentOperator.Name)
.ToLookup(t => t.to, t => t.notification);
thanks!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.