Rahul Makwana Rahul Makwana - 3 months ago 13x
SQL Question

Dapper's parameterized Update and Insert?

I am using Dapper for my windows C# forms application. I noticed that most of their CRUD operations take class name as parameter.
For example two tables as below :

"Employee" Table
Column Name | Data Type |
EmpName | string |
EmpNo | string |

public class Employee
public string EmpNo {get;set;}
public string EmpName {get;set;}

"User" Table
Column Name | Data Type |
UserName | string |
UserNo | string |
public class User
public string UserNo {get;set;}
public string UserName {get;set;}

eg. var users= connection.Query<User>("select * from User" );
var employees = connnection.GetList<Employee>();

will do the appropriate tasks.
but, as per my knowledge
connection.Insert<User>(user); or connection.Update<Employee>(emp);
does not exist.
Please correct me if I am wrong, is there any work around to have Update and Insert with letting dapper know the class type ?
I am well aware about
, in fact I am using those right now. Is there anyway possible to make it as easy as
is ?


Thanks to Marc Gravell. I found it here. It does implement Insert<ClassName>(obj) and Update<ClassName>(obj).