I'm trying to find a more elegant way of pulling information from my db to my web application. Currently I pull all data in my table and use only two columns' data. It was suggested that I look into using SelectMany() to accomplish this by being able to select only the columns I need.
I'm not entirely sure how to translate the msdn example to a linq statement using a linq-to-sql db.
My current statement is this:
return db.document_library_sitefiles .Where(item => item.SiteID == siteId) .Select(item => item.document_library) .GroupBy(item => item.Filename) .Select(group => group.OrderByDescending(p=>p.Version).First()) .Where(item => !item.Filename.Contains("*")).ToList(); My current attempt, which I know is wrong, looks like this:
return db.document_library_sitefiles .Where(item => item.SiteID == siteId) .SelectMany(item => item.document_library, (filename, filesize) => new { filename, filesize }) .Select(item => new { filename = item.document_library.filename, filesize = item.document_library.filesize }) .ToList(); Am I remotely close to getting my intended results?
Basically I want to get the data in my filename and filesize columns without pulling the rest of the data which includes file content (not my design or idea) so I'm not flooding my server with needless information just to show a simple data table of the files currently in this db.