Dapper not returning selected/desired rows -
i newbie dapper , copied sql script(from test doing entity framework) , tried return list of theses rows, returning entire class , not ones want!
using (idbconnection connection = new sqlconnection(@"data source=desktop-cd2uqi5\sqlexpress;initial catalog=servercontext;integrated security=true")) { var res = connection.query<table>("select images,addressfrom, table table.id = 1").tolist(); response = request.createresponse(httpstatuscode.ok, res); }
please help.
dapper doesn't processing of sql (well, does in very limited scenarios). so: whatever being returned because of your query - isn't changing query remove where
clause, , isn't inventing data.
if mean returning more columns expect, again: check query. 1 shown in question isn't valid (trailing comma in select
), can't comment based on question. check rogue *
.
so: take query, , try running ssms or sql tool; see rows , columns come back.
if table.id
unique / primary / identity / etc, yes seems odd more one, but: can't tell going on here, except: dapper running query.
minor points:
aslist()
preferabletolist()
- if expect 1 or @ 1 result, there methods more efficiently -
querysingle
etc if
id
isn't fixed, want use parameter, example:int id = ... var res = connection.query<table>( "select images,addressfrom, table table.id = @id", new { id } ).aslist();
Comments
Post a Comment