Using Dapper.Contrib it is as simple as this:
Insert list:
public int Insert(IEnumerable<YourClass> yourClass)
{
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
conn.Open();
return conn.Insert(yourClass) ;
}
}
Insert single:
public int Insert(YourClass yourClass)
{
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
conn.Open();
return conn.Insert(yourClass) ;
}
}
Update list:
public bool Update(IEnumerable<YourClass> yourClass)
{
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
conn.Open();
return conn.Update(yourClass) ;
}
}
Update single:
public bool Update(YourClass yourClass)
{
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
conn.Open();
return conn.Update(yourClass) ;
}
}
Source: https://github.com/StackExchange/Dapper/tree/master/Dapper.Contrib