The project hasRetrieve PasswordFunction, I am very happy to do it by myself, hey.
There is no problem after testing many times. The results were accidentally discovered by others.DatabaseInExpiration time (expireddate)AndCurrent Time (datetime. Now)Exist4 minutes or moreDifference", I always takeDatetime. NowThe current time is compared!
First, let's take a look at the following line.Code,
VaRModelcode = loadrepository. getentities <entity. verification_code> (). Where (I => I. Code. Equals (CODE) & I. expireddate> =Datetime. Now). Firstordefault ();
According to SQL Server Profiler, I found that: = "[extent1]. [expireddate]> = getdate ():
Maybe you think there may be no problem, but I looked at the SQL parsed by the query analyzer, And the datetime. Now in the obtained SQL is changed to getdate (). What is the problem;
Exec sp_executesql n'Select top (1)[Extent1]. [verificationid] as [verificationid], [extent1]. [userid] as [userid], [extent1]. [Code] as [Code], [extent1]. [adddate] as [adddate], [extent1]. [expireddate] as [expireddate], [extent1]. [Status] as [Status] from [DBO]. [verification_code] as [extent1] Where ([extent1]. [Code]= @ P _ LINQ _ 0) and ([extent1]. [expireddate] >=( getdate ()))
', N'@ P _ LINQ _ 0 varchar (8000)',
@ P _ LINQ _ 0 ='F784222508ce4e859108fd0c8b95df8f'
So I tried to select getdate (); and found that there is an error between the real getdate () and the current time.
I may understand,Datetime. NowIn the WHERE clause, comparison is not allowed. Because LINQ can only be compared with a value. Therefore, you must convert it to a value first.
Modify as follows:
VaR Datetime=Datetime. Now;VaRModelcode = loadrepository. getentities <entity. verification_code> (). Where (I => I. Code. Equals (CODE) & I. expireddate> =Datetime). Firstordefault ();
Check the SQL statement according to the SQL Server Profiler. The problem is solved, and datetime. Now is back.@ P _ LINQ _ 1 ='2013-05-28 15:25:37.8470000'
Exec sp_executesql n ' Select top (1) [Extent1]. [verificationid] as [verificationid], [extent1]. [userid] as [userid], [extent1]. [Code] as [Code], [extent1]. [adddate] as [adddate], [extent1]. [expireddate] as [expireddate], [extent1]. [Status] as [Status] from [DBO]. [verification_code] as [extent1] Where ([extent1]. [Code] = @ P _ LINQ _ 0) and ([extent1]. [expireddate] >=@ P _ LINQ _ 1)' ,
N ' @ P _ LINQ _ 0 varchar ( 8000 ), @ P _ LINQ _ 1 datetime ' ,
@ P _ LINQ _ 0 = ' F784222508ce4e859108fd0c8b95df8f ' ,
@ P _ LINQ _ 1 = ' 2013 - 05 - 28 15 : 25 : 37.8470000 '
Summary:I hope you don't want to cook like me. Maybe I am the only one to make this mistake. The details really make people feel that learning is a pleasure!