Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why dapper return Int64 ? #524

Closed
cdmin207078 opened this issue May 27, 2016 · 7 comments
Closed

why dapper return Int64 ? #524

cdmin207078 opened this issue May 27, 2016 · 7 comments

Comments

@cdmin207078
Copy link

var sql = @"select count(1) from Products;
                            select * from Products order by ProductId asc limit @ItemsPerPage Offset @Offset";

                using (var multi = _db.Connection.QueryMultiple(sql, new { ItemsPerPage = page.ItemsPerPage, Offset = (page.CurrentPage - 1) * page.ItemsPerPage }))
                {
                    var totalitems = multi.Read<int>().Single();
                    var data = multi.Read<Product>().ToList();
                }

Above is wrong. and push a `System.InvalidCastException'

If I change the following way ,it's correct ?

var totalitems = multi.Read<Int64>().Single();

Is a Bug ?

However, the query does not have this problem.

@mgravell
Copy link
Member

What version of dapper are you using? I believe this is already addressed
in current builds.

On Fri, 27 May 2016 08:51 天雨流芳, [email protected] wrote:

var sql = @"select count(1) from Products; select * from Products order by ProductId asc limit @ItemsPerPage Offset @offset";

            using (var multi = _db.Connection.QueryMultiple(sql, new { ItemsPerPage = page.ItemsPerPage, Offset = (page.CurrentPage - 1) * page.ItemsPerPage }))
            {
                var totalitems = multi.Read<int>().Single();
                var data = multi.Read<Product>().ToList();
            }

Above is wrong. and push a `System.InvalidCastException'

If I change the following way ,it's correct ?

var totalitems = multi.Read().Single();

Is a Bug ?

However, the query does not have this problem.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#524, or mute the
thread
https://github.com/notifications/unsubscribe/AABDsGBDVND7WFEs14u0MpM6wGdUZIEvks5qFqKSgaJpZM4IoQbV
.

@cdmin207078
Copy link
Author

cdmin207078 commented May 27, 2016

Thank you for your reply.
I got it from nuget. The version is Dapper.1.42 for .net45

You can try the following case:

var sql = "select 1 as A;select 2 as B";
 using (var multi = _db.Connection.QueryMultiple(sql))
 {
         var a = multi.Read<int>().Single();
         var b = multi.Read<int>().Single();
 }

image

Is it because I am using the database is SQLite ??

@mgravell
Copy link
Member

Again, which version of dapper are you using? It would be worth trying
the latest. Because of .net-core, many of the recent builds have been
marked pre-release, but they are absolutely fine for regular .net (it is
only the .net-core part that is really pre-release). I strongly suggest you
try on the latest version (1.50.0-rc2a), and see if it now works. I suspect
it will work fine.

To install a pre-release version from nuget, either use:

Install-Package Dapper -Pre

(in the package manager console), or if you are using the IDE UI tools,
check the "Include prerelease" checkbox.

On 27 May 2016 at 09:28, 天雨流芳 [email protected] wrote:

Thank you for your reply.
I got it from nuget.

You can try the following case:

var sql = "select 1 as A;select 2 as B";
using (var multi = _db.Connection.QueryMultiple(sql))
{
var a = multi.Read().Single();
var b = multi.Read().Single();
}

[image: image]
https://cloud.githubusercontent.com/assets/1762278/15602410/b0f6f066-2427-11e6-9a64-8c957f8fe0ee.png

Is it because I am using the database is SQLite


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#524 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AABDsFz48tsXJEmxZ33OQYQUCuAgjSXOks5qFqs5gaJpZM4IoQbV
.

Regards,

Marc

@mgravell
Copy link
Member

Now that I'm back at a PC, I've tested this locally, and I can confirm
there is a bug here; the following is fine:

i = db.Query<int>("select cast(1 as bigint);").Single();
j = db.QuerySingle<int>("select cast(1 as bigint);");

However, the similar via the multi-reader is broken:

            using (var multi = db.QueryMultiple("select cast(1 as

bigint); select cast(2 as bigint)"))
{
i = multi.Read().Single(); // breaks
j = multi.ReadSingle();
}

I will investigate and fix.

On 27 May 2016 at 09:53, Marc Gravell [email protected] wrote:

Again, which version of dapper are you using? It would be worth trying
the latest. Because of .net-core, many of the recent builds have been
marked pre-release, but they are absolutely fine for regular .net (it is
only the .net-core part that is really pre-release). I strongly suggest you
try on the latest version (1.50.0-rc2a), and see if it now works. I suspect
it will work fine.

To install a pre-release version from nuget, either use:

Install-Package Dapper -Pre

(in the package manager console), or if you are using the IDE UI tools,
check the "Include prerelease" checkbox.

On 27 May 2016 at 09:28, 天雨流芳 [email protected] wrote:

Thank you for your reply.
I got it from nuget.

You can try the following case:

var sql = "select 1 as A;select 2 as B";
using (var multi = _db.Connection.QueryMultiple(sql))
{
var a = multi.Read().Single();
var b = multi.Read().Single();
}

[image: image]
https://cloud.githubusercontent.com/assets/1762278/15602410/b0f6f066-2427-11e6-9a64-8c957f8fe0ee.png

Is it because I am using the database is SQLite


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#524 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AABDsFz48tsXJEmxZ33OQYQUCuAgjSXOks5qFqs5gaJpZM4IoQbV
.

Regards,

Marc

Regards,

Marc

@cdmin207078
Copy link
Author

Well, thank you for your answer .

@mgravell mgravell reopened this May 27, 2016
@mgravell
Copy link
Member

I'm re-opening this to track as I fix it.

mgravell added a commit that referenced this issue May 27, 2016
…until I get the latest tooling installed)
@mgravell
Copy link
Member

This will be fixed in any build after 1.50.0-rc2a. Until then: you may have to either a: cast the data in your RDBMS, or b: ask for a long, then cast to an int in C#.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants