Skip to content
/ DbMap Public

A library with extensions for DbConnection to execute queries and optionally map the results to types

License

Notifications You must be signed in to change notification settings

hbbq/DbMap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DbMap

A library with extensions for DbConnection to execute queries and optionally map the results to types

Possibility to execute a query directly from a DbConnection instance and casting the result to (almost) any type:

using (var cn = new SQLiteConnection(connectionString))
{
    cn.Open();
    var count = cn.ExecuteScalar<int>("select count(*) from MyTable");
}

Possibility to execute a query and return a list of objects of (almost) any type:

private class Person
{
   public int Id { get; set; }
   public string Firstname { get; set; }
   public string Lastname { get; set; }
}

private static void Main()
{
    var connectionString = "<ConnectionString>";
    using (var cn = new SQLiteConnection(connectionString))
    {
        cn.Open();
        var persons = cn.Execute<Person>("select id, firstname, lastname from Persons");
    }   
}

Possibility to send parameters to query as instance of an anonymous (or named) type:

using (var cn = new SQLiteConnection(connectionString))
{
    cn.Open();
    var id = cn.ExecuteScalar<int>(
        "select id from Persons where firstname = @firstname and lastname = @lastname",
        new
        {
            filename = "John",
            lastname = "Doe",
        });
}

About

A library with extensions for DbConnection to execute queries and optionally map the results to types

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages