I have a LINQ to SQL query that returns a grouped collection of Sponsor
objects like so:
var result = ( from s in db.Sponsors
join sl in sb.SponsorLevels on s.SponsorLevelId equals sl.SponsorLevelId
select new Sponsor
{
Name = s.Name,
Level = sl.LevelName
}
).GroupBy(s => s.LevelName);
My application already uses an interface defined as...
public interface ISponsorLevelGroup
{
string Level { get; set; }
IList<Sponsor> Sponsors { get; set; }
}
...where the Level
string property is the grouping key from the LINQ result. I ultimately want to get the LINQ result into an IList<ISponsorLevelGroup>
.
Logically my LINQ to SQL result is a collection of ISponsorLevelGroup
objects, but I am not sure on how to most efficiently map one to the other. I seem to be relegated to manually traversing the groups and the collections within them at this point and copying the data into objects which implement my specific interface. Is there a better way? How can I most effectively push my LINQ result into an IList<ISponsorLevelGroup>
?