2014-09-06 17 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

相关问题