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 |
--------------------------
Employee.cs
[Table("Employee")]
public class Employee
{
[Key]
public string EmpNo {get;set;}
public string EmpName {get;set;}
}
"User" Table
Column Name | Data Type |
-------------------------
UserName | string |
UserNo | string |
--------------------------
User.cs
[Table("User")]
public class User
{
[Key]
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 Query()
and Execute()
, in fact I am using those right now. Is there anyway possible to make it as easy as GetList(ClassName);
is ?