我在 Windows C# 表单应用程序中使用 Dapper。我注意到他们的大部分 CRUD 操作都以类名作为参数。例如下面的两个表:
"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>();
Run Code Online (Sandbox Code Playgroud)
会做相应的任务。但是,据我所知connection.Insert<User>(user); or connection.Update<Employee>(emp);,不存在。如果我错了,请纠正我,是否有任何解决方法可以让 dapper 知道类类型来更新和插入?我很清楚Query()并且Execute()实际上我现在正在使用它们。有没有可能让它变得如此简单GetList(ClassName);?
| 归档时间: |
|
| 查看次数: |
13573 次 |
| 最近记录: |