Select multiple columns using Entity Framework

前端 未结 7 1359
逝去的感伤
逝去的感伤 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:13

    You either want to select an anonymous type:

    var dataset2 = from recordset 
                   in entities.processlists 
                   where recordset.ProcessName == processname 
                   select new 
                   {
                    recordset.ServerName, 
                    recordset.ProcessID, 
                    recordset.Username
                   };
    

    But you cannot cast that to another type, so I guess you want something like this:

    var dataset2 = from recordset 
                   in entities.processlists 
                   where recordset.ProcessName == processname 
    
                   // Select new concrete type
                   select new PInfo
                   {
                    ServerName = recordset.ServerName, 
                    ProcessID = recordset.ProcessID, 
                    Username = recordset.Username
                   };
    
    0 讨论(0)
提交回复
热议问题