Entity Framework 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,
CONSTRAINT [PK_Activations] クラスター化された主キー
これは、特定の行を取得するために使用するコードです。
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 許容に設定すると、null が返されました。