Asp.net 如何使用EF4.1筛选可为空的DateTime字段?
我有一个带有可空DateTime字段的表:Asp.net 如何使用EF4.1筛选可为空的DateTime字段?,asp.net,entity-framework-4.1,nullable,Asp.net,Entity Framework 4.1,Nullable,我有一个带有可空DateTime字段的表: CREATE TABLE [dbo].[myTable]( [ID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL, ... [FinishedDate] [datetime] NULL, etc... 当我尝试这个: var activeThings = from foo in _context.myTable where foo.Finish
CREATE TABLE [dbo].[myTable](
[ID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
...
[FinishedDate] [datetime] NULL,
etc...
当我尝试这个:
var activeThings = from foo in _context.myTable
where foo.FinishedDate == null
select foo;
foreach ( var thing in activeThings ) {
... do some stuff ...
}
我得不到任何回报。如何根据空值筛选此项
var activeThings = from foo in _context.myTable
where !foo.FinishedDate.HasValue //foo.FinishedDate.HasValue==false
select foo;
HasValue返回布尔值
is true=>不为空
为false=>null