Jay
Jay

Reputation: 59

What is the use of sql builder in PetaPoco?

I have this code in petapoco

public List<T> Fetch<T>(Sql sql)
{
            return Fetch<T>(sql.SQL, sql.Arguments);
}

Which inherently calling Fetch method which takes a string as parameter. Then why do we need sql builder in petapoco?

Upvotes: 1

Views: 3281

Answers (1)

William Xifaras
William Xifaras

Reputation: 5312

Sql.Builder is a fluent API and gives the ability to conditionally build SQL. Which makes formatting SQL strings easy and provides a mechanism to use proper parameter replacements to protect from SQL injection.

Example not tested

var sql = PetaPoco.Sql.Builder()
    .Select("*")
    .From("Orders.Product")
    .Where("OrderID = @0", id);

From PetaPoco documentation:

Fetch returns a List<> of POCO's

Upvotes: 3

Related Questions