Select two columns from the table via linq

c#, linq

Solution

var query = DBContext.Table1.Where(c => c.FacilityID == facilityID && c.FilePath != null && c.TimeStationOffHook < oldDate)
                            .OrderBy(c => c.FilePath)
                            .Skip(1000)
                            .Take(1000)
                            .Select(c => new { c.FilePath, c.FileName })
                            .ToList();
foreach(var t in query)
{
    Console.WriteLine(t.FilePath +"\\"+t.FileName);
}

You need to use `Select`.

Problem

I use the query below to get all columns(20 more) in Entity Framework Linq. Because of out of memory exception, I only want to get two of them. One is "FileName", the other one is "FilePath". How to modify my code? ``` var query = DBContext.Table1 .Where(c => c.FacilityID == facilityID && c.FilePath != null && c.TimeStationOffHook < oldDate) .OrderBy(c => c.FilePath) .Skip(1000) .Take(1000) .ToList(); foreach(var t in query) { Console.WriteLine(t.FilePath +"\\"+t.FileName); } ```

Original source