2014-09-06 21 views
0

我有一個類(vb.net),我想在LinqPad中查詢一些數據。我已經和一些來自「Linq in Action」的例子一起工作,所以他們使用某種類型的數據來解釋查詢。但我無法找到關於如何導入或編寫自己的類的任何內容。有人可以幫我嗎?在LinqPad中創建自己的數據示例

我的班級是這樣的:

Public Class Employee 
    Public Property ID As Integer 
    Public Property Salery As Integer 
    Public Property Name As String 
    Public Property Department As String 
    Public Property Gender As String 

    Public Shared Function GetAllEmployees() As List(Of Employee) 
     Return New List(Of Employee) From { _ 
      New Employee With {.ID = 1, .Name = "Mark", .Department = "HR", .Gender = "Male", .Salery = 12000}, 
      New Employee With {.ID = 2, .Name = "Sandra", .Department = "IT", .Gender = "Female", .Salery = 2000} _ 
     } 
    End Function 
End Class 

回答

1

您可能忽略關於使用LINQPad有兩件事情:

  • 將語言設置爲「VB程序」,並把階級其中評論說來。
  • 使用Dump方法輸出表達式。 (對於「VB表達式」,Dump被自動調用。)

這裏是一個例子。 (請注意,您可能正在使用SQL查找語法。)

Sub Main 

    Employee.GetAllEmployees() _ 
     .Where(Function (employee) employee.Department = "HR") _ 
     .Dump() 

    Dim hrEmployees = From employee In Employee.GetAllEmployees() 
     Where employee.Department = "HR" 
    hrEmployees.Dump() 

End Sub 

' Define other methods and classes here 
Public Class Employee 
    Public Property ID As Integer 
    Public Property Salery As Integer 
    Public Property Name As String 
    Public Property Department As String 
    Public Property Gender As String 

    Public Shared Function GetAllEmployees() As List(Of Employee) 
     Return New List(Of Employee) From { _ 
      New Employee With {.ID = 1, .Name = "Mark", .Department = "HR", .Gender = "Male", .Salery = 12000}, 
      New Employee With {.ID = 2, .Name = "Sandra", .Department = "IT", .Gender = "Female", .Salery = 2000} _ 
     } 
    End Function 
End Class 
+0

我明白了!太好了,非常感謝! – ruedi 2014-09-07 09:27:30

相關問題