quaiton89 / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

Dapper do not understand timestamp type #123

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Dapper do not understand timestamp type ?

Ideally Timestamp is the binary field in MS sql server. When I send 
Byte[] type to my store procedure then, It gives me SqlDateTime overflow 
exception as follow.

Some error occuerd, Error: SqlDateTime overflow. Must be between 1/1/1753 
12:00:00 AM and 12/31/9999 11:59:59 PM..

My store proc looks below

ALTER PROCEDURE [dbo].[UpdateRole]
(
                       @RoleID INT OUTPUT,
                       @RoleName VARCHAR(50),                       

                       @TimeStamp timestamp                 
                      )
{
Begin
Update Role
           SET RoleName=@RoleName ,
       Where  RoleID= @RoleID and [TimeStamp] = @TimeStamp
End
}

Original issue reported on code.google.com by bijaykap...@gmail.com on 22 Nov 2012 at 3:54

GoogleCodeExporter commented 8 years ago
Confirms it, It was giving error since, I used return type as Object for this 
timestamp  timestamp fields, When Byte[] is used it worked again, seems you can 
not pass object type to your stored procedure otherwise your dapper will be 
blow up with error. 

Original comment by bijaykap...@gmail.com on 22 Nov 2012 at 4:27

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Can you show a *complete* (i.e. including the calling code) example that fails? 
The following works fine:

            connection.Execute("create table #issue123 (id int not null identity(1,1), val int not null, ts timestamp not null)");
            var row = connection.Query("insert #issue123 (val) output INSERTED.id, INSERTED.ts values (@val)", new { val = 123 }).Single();
            byte[] ts = row.ts;
            int id = row.id;
            int count = connection.Query<int>("update #issue123 set val = @val where id = @id and ts = @ts select @@rowcount", new { val = 456, id, ts }).Single();
            count.IsEqualTo(1);
            int val = connection.Query<int>("select val from #issue123 where id = @id", new { id }).Single();
            val.IsEqualTo(456);

Alternatively, can you please give an indication of what type of value you are 
supplying into @TimeStamp.

Original comment by marc.gravell on 22 Nov 2012 at 7:47

GoogleCodeExporter commented 8 years ago
In particular, the dapper code **does not include** any reference to 
SqlDateTime, so dapper isn't doing a conversion to that. And SqlDateTime is 
**not** an appropriate date type for a timestamp. A timestamp *is not a time* - 
it is a blob.

Additional: for that reason (confusion), the keyword "timestamp" is formally 
marked obsolete in MSDN; you should use "rowversion", which is identical, but 
less confusing (it doesn't make people think "time")

Original comment by marc.gravell on 22 Nov 2012 at 7:50

GoogleCodeExporter commented 8 years ago
No further example provided; closing

Original comment by marc.gravell on 6 Aug 2014 at 3:33