c# - Lambda 在日期范围之间加入

标签 c# sql lambda

我需要将一张周末餐 table 连接到另一张餐 table 上的结果。

如何在 lambda 中编写此 sql 查询

SELECT * FROM DBS
INNER JOIN WeekEnding WE 
ON DBS.ResultDateTime BETWEEN WE.StartDateTime AND WE.EndDateTime

我不确定如何加入开始周末和结束周末之间的选择器。这就是我的

var newQry = qry.Join(_context.WeekEnding, dbs => dbs.ResultDateTime, we => 
we.StartDateTime && we.EndDateTime, 
(res, we) => new DBS
{
        ....        
});

最佳答案

您可以使用多个from 子句来实现交叉连接,然后根据条件进行过滤:

from we in _context.WeekEnding
from dbs in _context.DBS
where dbs.ResultDateTime >= we.ResultDateTime
&& dbs.ResultDateTime <= we.EndDateTime
select new (we, dbs)

关于c# - Lambda 在日期范围之间加入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56043726/

相关文章:

amazon-web-services - 错误 : exec: \"app.handler\": executable file not found in $PATH", "errorType": "Runtime.InvalidEntrypoint"

c# - 解析动态 JSON

sql - 使用 Query 在 SQL Server 中查找所有使用游标的存储过程

c# - 并行化作业的更好方法

sql - 需要帮助从字符串中提取子字符串直到特定长度之前的最后一个空格

sql - 删除表中的选定行(如何提高速度)

.net - 使用对象属性作为字典中的键

c# - Visual Studio 2010 - 卸载 NuGet

c# - List<string> 和 IEnumerable<String> 有什么区别?

c# - 必须实现通用的小于和大于操作