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.
- Host: GitHub
- URL: https://github.com/null511/dapper.scripts
- Owner: null511
- License: apache-2.0
- Created: 2017-09-06T22:08:38.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-03-02T22:11:21.000Z (almost 2 years ago)
- Last Synced: 2025-03-24T03:04:59.688Z (10 months ago)
- Topics: dapper, external, script, sql
- Language: C#
- Size: 1.41 MB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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).