c# - 同一行上的 Linq 更多条件

标签 c# linq linq-to-sql

嗨,我有以下查询来获取一些行

Where(x =>  (x.Year >= 2012 && x.Month >= 12) && (x.Year <= 2013 && x.Month < 2))

这应该返回我 2012.122013.1但当然它不会返回任何行,因为 month >=12 没有任何行和month <2 ,所以我的问题是如何仅检查年份与某某相同的行的月份?

例如。检查month >=12仅适用于 year >= 2012 and check month <2 的行仅适用于 year <= 2013 的行.

我应该提到我的 sql 表没有日期时间字段

[Year] [int] NOT NULL,
[Month] [int] NOT NULL,
[Value] [float] NOT NULL,

最佳答案

例如,

Where(x => x.Year*12+x.Month >= 2012*12+12  && x.Year*12+x.Month < 2013*12+2)

关于c# - 同一行上的 Linq 更多条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16507133/

相关文章:

c# - C#应用程序错误处理的问题

asp.net - 有没有任何工具可以查看针对数据库运行的查询?

visual-studio - Visual Studio 和 LINQ : placing the DBML file in separate directory in the project

c# - Linq-to-Sql 设计器中的自定义表达式

c# - 通过 HttpClient 使用外部 REST Web 服务的存储库模式示例?

c# - 反射发射 : how to build constructor for this

c# - LINQ To SQL 不提交更改

c# - VB.Net 与 C# 表达式树的差异

c# - 使用 LINQ 从 xml 创建实体对象的最佳方法

c# - 使用 Linq to Entities 插入现有行的副本