Select multiple columns using Entity Framework

前端 未结 7 1374
逝去的感伤
逝去的感伤 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 07:59

    Here is a code sample:

    var dataset = entities.processlists
        .Where(x => x.environmentID == environmentid && x.ProcessName == processname && x.RemoteIP == remoteip && x.CommandLine == commandlinepart)
        .Select(x => new PInfo 
                     { 
                          ServerName = x.ServerName, 
                          ProcessID = x.ProcessID, 
                          UserName = x.Username 
                     }) AsEnumerable().
                   Select(y => new PInfo
                   {
                       ServerName = y.ServerName,
                       ProcessID = y.ProcessID,
                       UserName = y.UserName 
                   }).ToList();
    

提交回复
热议问题