An open API service indexing awesome lists of open source software.

https://github.com/null511/dapper.scripts

Extension of Dapper which supports binding a sql-script collection to a sql-connection.
https://github.com/null511/dapper.scripts

dapper external script sql

Last synced: 10 months ago
JSON representation

Extension of Dapper which supports binding a sql-script collection to a sql-connection.

Awesome Lists containing this project

README

          

# Dapper Scripts
Extension of Dapper which supports binding a collection of SQL scripts to a `SqlConnection`.

Avoid embedding SQL text strings into your code, and leverage syntax hightlighting, by storing your SQL operations in external *.sql files. Dapper scripts binds a collection of key-based sql strings to a connection factory, allowing you to keep your database code clean. All extensions match the original dapper commands, but using a _*Script_ suffix.

**Setup**
```c#
static class Sql
{
public static SqlScriptConnectionFactory SampleDatabase {get;}

static Sql()
{
var scripts = new SqlScriptCollection();
scripts.Add.FromFile("test-query", "query.sql");

DatabaseName = new SqlScriptConnectionFactory(scripts);
DatabaseName.ConnectionString = "Server: ...;";
}
}
```

_Note:_ For best results, it is recommended to use _Embedded Content_ as the Content Type for your sql files. This will allow them to be stored within your assembly file after compiling.

**Usage**
```c#
using (var connection = Sql.SampleDatabase.Connect()) {
return connection.QueryScript("test-query", new {arg = value});
}
```

For more examples, visit the [WiKi](https://github.com/null511/Dapper.Scripts/wiki).