I've got a problem and need some help. I've got a list of objects which have many properties, but only two are important "From" and "To".
objectData { "From" : "ContactDTO", "To" : ["ContactDTO"], ...//other fields }
contactDto { "email" : "string", ... other fields }
and I need to return new list with unique entries "From", array of contacts "To" without duplicates.
Test Data:
{
"From": { "email" : "[email protected]"},
"To": "[{ "email" : "[email protected]"}, { "email" : "[email protected]"}]"
},
{
"From": { "email" : "[email protected]"},
"To": "[{ "email" : "[email protected]"}, { "email" : "[email protected]"}]"
},
{
"From": { "email" : "[email protected]"},
"To": "[{ "email" : "[email protected]"}, { "email" : "[email protected]"}]"
},
Should Return:
[
"From": { "email" : "[email protected]"},
"To": "[{ "email" : "[email protected]"}, { "email" : "[email protected]"}, { "email" : "[email protected]"}]"
{
"From": { "email" : "[email protected]"},
"To": "[{ "email" : "[email protected]"}, { "email" : "[email protected]"}]"
}
]
I know how to do it in a loop, but I would like to make it more readable and clean with using linq.
I've tried:
var newData = data.Where(x => IsReview(x))
.Select(x =>
new {
From = x.From.EmailAddress,
List = x.To.Select(z => z.EmailAddress).ToList()
}).GroupBy(y => y.From);
List?