Select multiple columns using Entity Framework

前端 未结 7 1375
逝去的感伤
逝去的感伤 2021-01-31 07:10

Maybe an easy question, but can\'t find it easily so forgive me =) I try to select multiple columns. The statement I use is:

var dataset2 = from recordset in ent         


        
7条回答
  •  旧巷少年郎
    2021-01-31 08:10

    It's correct way to get data in specified type:

    var dataset = entities.processlists
             .Where(x => x.environmentID == environmentid && x.ProcessName == processname && x.RemoteIP == remoteip && x.CommandLine == commandlinepart)
             .Select(x => new { x.ServerName, x.ProcessID, x.Username })
             .ToList() /// To get data from database
             .Select(x => new PInfo()
                  { 
                       ServerName = x.ServerName, 
                       ProcessID = x.ProcessID, 
                       Username = x.Username 
                  });
    

    For more information see: The entity cannot be constructed in a LINQ to Entities query

提交回复
热议问题