【发布时间】:2014-01-30 18:26:09
【问题描述】:
我如何在 Linq 中做到这一点?
SELECT [...] WHERE A.Year = YEAR(ISNULL(B.Date, '1900-01-01'))
字段的数据类型:
A.Year : int not null
B.Date : datetime null
【问题讨论】:
我如何在 Linq 中做到这一点?
SELECT [...] WHERE A.Year = YEAR(ISNULL(B.Date, '1900-01-01'))
字段的数据类型:
A.Year : int not null
B.Date : datetime null
【问题讨论】:
LINQ to 实体:
(...)
where a.year == SqlFunctions.DatePart("y", b.date ?? new DateTime(1900, 1, 1))
LINQ to SQL:
(...)
where a.year == (b.date ?? new DateTime(1900, 1, 1)).Year
【讨论】:
不知道您的数据结构在 .NET 方面是什么样的......
var defaultDate = new DateTime(1900, 1, 1);
var result = from x in xxx
where x.Year == (b.Date ?? defaultDate).Year
【讨论】:
.Where( f => f.Year == (B.Date ?? new DateTime(1990, 1,1)).Year)
【讨论】: