Mad.MSSql

Helper library for managing and querying SQL databases.


SqlConn

Used for holding the SQL connections.

    var conn = new SqlConn(...);

SqlQuery

Used for holding the SQL query string and parameters.

    var query = new SqlQuery("SELECT * FROM [Users] WHERE [Id] = @Id").AddParameter("Id", "123");

SqlEngine

Use this for excecuting SQL queries. This is a static class.

ExecuteNonQueryExcecute a query that don't return anything.SqlEngine.ExecuteNonQuery(query, conn)
ExecuteReaderSingleSetExcecute a query that returns a single dataset.SqlEngine.ExecuteReaderSingleSet(query, conn)
ExecuteReaderExcecute a query that returns multiple data sets.SqlEngine.ExecuteReader(query, conn)
CreateLocalDbIfDontExistCreates a LocalDb.SqlEngine.CreateLocalDbIfDontExist("C:\\Temp\\LocalDbs\\", "TestDb1")

SqlTable

You can use the SqlTable and SqlColumn to create sql tables. There are some helper methods in the SqlFac to create a table based on a C# type.

Create Table from C# Class

        var conn = new SqlConn(...);
        var table = SqlFac.Table<AccountEntity>();
        SqlEngine.ExecuteNonQuery(table.ToCreateTableIfNotExistQuery(), conn);

Drop All Data from Table

        var conn = new SqlConn(...);
        var table = SqlFac.Table<AccountEntity>();
        SqlEngine.ExecuteNonQuery(table.ToDropAllDataQuery(), conn);

Drop Table

        var conn = new SqlConn(...);
        var table = SqlFac.Table<AccountEntity>();
        SqlEngine.ExecuteNonQuery(table.ToDropTableQuery(), conn);