0

I'm facing a problem in PetaPoco, and I can't figure it out.

I'm using this code :

var db = new OracleConnection(_connectionString);

var query = Sql.Builder;
query.Append("SELECT * FROM City WHERE ID = @0", 1);

return db.Query<City>(query.SQL).ToList();

PetaPoco is not adding the parameter to my sql query.

PetaPoco

This is an example from their official website :

var id=123;
var sql=PetaPoco.Sql.Builder
          .Append("SELECT * FROM articles")
          .Append("WHERE article_id=@0", id);

For you information : I'm using the last version of PetaPoco (5.0.1)

Wassim AZIRAR
  • 10,823
  • 38
  • 121
  • 174

2 Answers2

2

I'd skip Sql.Builder (it's gaining you nothing here), and as a side-note, use db.Fetch as it already returns a List. So:

var query = "SELECT * FROM City WHERE ID = @0";
return db.Fetch<City>(query, 1);
Todd Menier
  • 37,557
  • 17
  • 150
  • 173
1

Just query to the Query<> method, not just the sql. Otherwise you need to pass the Arguments as the second parameter.

Schotime
  • 15,707
  • 10
  • 46
  • 75