c# - Dapper.net use query into the Dictionary -


my sql :

select (select count(*) tblrmember sex=1) male,  (select count(*) tblrmember sex=2) female,  (select count(*) tblrmember sex=0) unkown 

i want dapper.net return dictinary this:

keys:male,female,nukown value:10,30,50 

i have see how map dictionary object database results using dapper dot net? ,but can not work!

how use todictionary or other way implement want

var mydictionary = sqlconnection.query(strsql).todictionary(??); 

thanks!

first change query single one:

select case when sex = 1 'male'             when sex = 2 'female'             when sex = 0 'unknown'        end sex, count(*) cnt tblrmember group sex 

as see sex numerical, either have select coumn name (sexname?) or change in code. after that:

var mydictionary = sqlconnection.query(strsql)                     .todictionary(x => x.sex.tostring(), x => (int)x.cnt); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -