我使用實體框架5,數據庫優先。實體框架設置日期時間爲空或分鐘
我正在做一些我以前做過很多次的事情,但由於某種原因,它無法正常工作。
我的表被定義爲:
CREATE TABLE [dbo].[ActivationQueue](
[ID] [int] IDENTITY(1,1) NOT NULL,
[username] [nvarchar](255) NOT NULL,
[email] [nvarchar](255) NOT NULL,
[ActivationRequested] [datetime] NOT NULL,
[ActivationEmailSent] [datetime] NOT NULL,
[AccountActivated] [datetime] NOT NULL,
[ActivationAttempts] [int] NULL,
[ActivationKey] [uniqueidentifier] NULL,
約束[PK_Activations] PRIMARY KEY CLUSTERED
這是我使用來檢索特定的行的代碼:
ActivationQueue accountActivation = DbSet.FirstOrDefault(a => a.username.ToLower() == userName)
當我使用DbSet.FirstOrDefault()
獲取第一行,ActivationEmailSent列總是返回SQLDateTime.MinValue()
即使它有一個正確的值。 ActivationRequested列始終返回正確的值。
我用過SQL分析器,當我運行下面的SQL時,我得到正確的DateTime
值。
exec sp_executesql N'SELECT TOP (1)
[Extent1].[ID] AS [ID],
[Extent1].[username] AS [username],
[Extent1].[email] AS [email],
[Extent1].[ActivationRequested] AS [ActivationRequested],
[Extent1].[ActivationEmailSent] AS [ActivationEmailSent],
[Extent1].[AccountActivated] AS [AccountActivated],
[Extent1].[ActivationAttempts] AS [ActivationAttempts],
[Extent1].[ActivationKey] AS [ActivationKey]
FROM [dbo].[ActivationQueue] AS [Extent1]
WHERE (LOWER([Extent1].[username])) = @p__linq__0',N'@p__linq__0 nvarchar(4000)',@p__linq__0=N'someusername'
這讓我的事情是,對於ActivationRequested
和ActivationEmailSent
的映射是相同的是定義(我只是用updateModel
在EDMX)。但ActivationRequested
返回正確的值,而ActivationEmailSent
回報SQLDateTime.Min
(1753-01-01 00:00:00.000
)
我不知道這是否會有所幫助,但是當我設置列是空的,它只是返回null。
在代碼中的某處,該值沒有設置。 – scartag 2013-03-17 22:15:31