1

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'

私が得たのは、 と のマッピングが定義ActivationRequestedActivationEmailSent同じであることです (私updateModelは edmx で使用したばかりです)。ただしActivationRequested、正しい値をActivationEmailSent返しますが、 SQLDateTime.Min( 1753-01-01 00:00:00.000)を返します

これが役立つかどうかはわかりませんが、列を null 許容に設定すると、null が返されました。

4

1 に答える 1

0

これに伴う可能性のある他の人の問題を見つけました。

DateTime列のmodel.storeプロパティの精度属性はNoneに設定されていましたが、エンティティの精度属性は3に設定されていました。

両方の精度属性をnoneに変更すると、問題が修正されました。

そもそもなぜそれが列の1つで機能し、同じマッピングを持っていたとしても他の列では機能しなかったのか、私はまだ困惑しています。

于 2013-03-19T09:32:28.173 に答える