Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 使用联接的list.longcount查询(Linq/Lambda)_Vb.net_Linq_Join_Lambda - Fatal编程技术网

Vb.net 使用联接的list.longcount查询(Linq/Lambda)

Vb.net 使用联接的list.longcount查询(Linq/Lambda),vb.net,linq,join,lambda,Vb.net,Linq,Join,Lambda,我有两个类对象列表(shift和Employees),我正试图使用它们创建联接。然后,我需要与搜索条件匹配的结果项的计数 下面是我正在使用的代码,但由于我找不到将结果作为特定“类型”传回的方法,因此它默认为布尔值,并警告我这将导致问题: ' Count Shifts for selected hour where: started before or on this "hour" AND ends after or during this "hour" and Department = fil

我有两个类对象列表(
shift
Employees
),我正试图使用它们创建联接。然后,我需要与搜索条件匹配的结果项的计数

下面是我正在使用的代码,但由于我找不到将结果作为特定“类型”传回的方法,因此它默认为布尔值,并警告我这将导致问题:

' Count Shifts for selected hour where: started before or on this 
"hour" AND ends after or during this "hour" and Department = filter 
value
intShift = Me.Shifts.LongCount(From myshift In Me.Shifts Join 
myEmp In Me.EmployeesList On myshift.EmployeeName Equals myEmp.Name 
Where myshift.Description = "Shift" And myshift.DateStart.Hour <= 
myHour.Hour And myshift.DateEnd.Hour >= myHour.Hour _
And myshift.DateStart.Date = myDay.Date And myEmp.Department = 
strFilter _ Or myshift.Description = "Overtime" And 
myshift.DateStart.Hour <= myHour.Hour And myshift.DateEnd.Hour 
>= myHour.Hour _
And myshift.DateStart.Date = myDay.Date And myEmp.Department = 
strFilter)
“计算所选小时的班次,其中:在此之前或当天开始
“小时”,并在此“小时”之后或期间结束,部门=过滤器
价值
intShift=Me.shift.LongCount(来自Me.shift中的myshift)
myshift上的myEmp In Me.employees列表。EmployeeName等于myEmp.Name
其中myshift.Description=“Shift”和myshift.DateStart.Hour=myHour.Hour_
myshift.DateStart.Date=myDay.Date和myEmp.Department=
strFilter或myshift.Description=“超时”和
myshift.DateStart.Hour=myHour.Hour_
myshift.DateStart.Date=myDay.Date和myEmp.Department=
strFilter(标准过滤器)
没有加入员工列表和匹配的员工搜索过滤器的搜索可以完美地工作,但无法将两者结合起来


我已经搜索了linq/lambda和内部连接示例,但似乎找不到将它们与
longcount
函数相结合的示例。

我试图根据您的代码片段组合一个最小的场景。 如果直接从查询中请求
Count
LongCount
,则结果与预期一致

    Dim Shifts() = {
        New With {.DateStart = #1/1/2014#,
                  .DateEnd = #1/2/2014#,
                  .Description = "Overtime",
                  .EmployeeName = "Darren"}
    }

    Dim EmployeesList() = {
        New With {.Name = "Darren",
                  .Department = "SO"}
        }

    Dim strFilter = "SO"
    Dim myHour = #1/1/2014#
    Dim myDay = myHour

    Dim query =
        From myshift In Shifts Join myEmp In EmployeesList _
        On myshift.EmployeeName Equals myEmp.Name _
        Where myshift.Description = "Shift" _
        And myshift.DateStart.Hour <= myHour.Hour _
        And myshift.DateEnd.Hour >= myHour.Hour _
        And myshift.DateStart.Date = myDay.Date _
        And myEmp.Department = strFilter _
        Or myshift.Description = "Overtime" _
        And myshift.DateStart.Hour <= myHour.Hour _
        And myshift.DateEnd.Hour >= myHour.Hour _
        And myshift.DateStart.Date = myDay.Date _
        And myEmp.Department = strFilter

    Console.WriteLine(query.Count)
    Console.WriteLine(query.LongCount)
Dim Shifts()={
新增{.DateStart=#1/1/2014#,
.DateEnd=#1/2/2014#,
.Description=“加班”,
.EmployeeName=“Darren”}
}
Dim EmployeesList()={
新增了{.Name=“Darren”,
.Department=“SO”}
}
Dim strFilter=“SO”
Dim myHour=#2014年1月1日#
昏暗的myDay=myHour
模糊查询=
从我的轮班制加入我的员工名单_
在myshift.EmployeeName上等于myEmp.Name_
其中myshift.Description=“Shift”_
而myshift.DateStart.Hour=myHour.Hour_
并且myshift.DateStart.Date=myDay.Date_
和myEmp.Department=strFilter_
或myshift.Description=“加班”_
而myshift.DateStart.Hour=myHour.Hour_
并且myshift.DateStart.Date=myDay.Date_
和myEmp.Department=strFilter
Console.WriteLine(query.Count)
Console.WriteLine(query.LongCount)