Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何使用EF4.1筛选可为空的DateTime字段?_Asp.net_Entity Framework 4.1_Nullable - Fatal编程技术网

Asp.net 如何使用EF4.1筛选可为空的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

我有一个带有可空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.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