给定一个看起来像这样的数据集:
Iqueryable<photos> which represents the following table in a database
DataTable table = new DataTable("Trip");
table.Columns.Add("Date", typeof(string));
table.Columns.Add("Location", typeof(string));
table.Columns.Add("PhotoName", typeof(string));
table.Rows.Add("1/1/2001", "Home", "Photo1.jpg");
table.Rows.Add("1/1/2001", "Home", "Photo2.jpg");
table.Rows.Add("1/2/2001", "Work", "Photo3.jpg");
table.Rows.Add("1/2/2001", "Work", "Photo4.jpg");
table.Rows.Add("1/3/2001", "Home", "Photo5.jpg");
我想创建以下按日期和位置分组的类的集合:
class PhotoCollection
{
string date;
string location;
IList<string> namesOfPhotos;
}
我开始:
from photo in photos
group photo by new { photo.date, photo.location };
问题:
既然项目已分组,是否可以巧妙地创建内联 PhotoCollection 的集合?