c# - 查询重复日期

标签 c# sql-server entity-framework linq-to-entities

我有两个表 Bus 和 Recurring。我想在指定日期搜索公共(public)汽车。如果搜索日期是星期一,则显示公交车;如果搜索日期是星期三,则不显示。

我想知道如何使用 LINQ to EF 创建查询。

Bus
===
Id   Name   From      To         DepartTime ArrivalTime, RecurringId
-------------------------------------------------------------------
01    Bus1  Yangon    Mandalay   20:00      4:00         01

经常性的:

Id  Mon Tue Web Thu Fri Sat Sun
--------------------------------
01  Y   Y   N   Y   N   Y   N

最佳答案

您的表格中没有任何内容表示有关特定日期的信息。因此,我假设您需要以下...

select * 
from 
    Bus as B
    inner join Recurring as R on R.Id == B.Id
where
    R.Mon = 1

...周一运行的所有公共(public)汽车。 LINQ to EF 中的相同内容是...

Bus[] buses = (from b in context.Bus
               join r in context.Recurring on r.id = b.id
               where r.Mon
               select b).ToArray(); 

关于c# - 查询重复日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28554176/

相关文章:

c# - 与 visual studio 2012 相比,visual studio 2013 是否删除或缺少任何功能

mysql - 使用 ssis 结果导入到 sql 以将数据移动到下一列

.net - 如何将 'Tags' 添加到我的简单博客文章类库和存储库中?

c# - .Select Vs .Include Vs .Select Many

c# - C# 中的 DrawString 居中文本

c# - 类库中的 Razor,缺少智能感知

c# - 服务无法启动,但确实启动了?

c# - 使用 .NET 将声明的字符串作为查询发送到 SQL Server 中

.net - 如何从 Windows docker 容器中的 .NET 应用程序连接到主机上运行的 SQL Server

asp.net - 来自数据库的 Entity Framework 更新模型不为 tt 类中新添加的表生成 cs 类