Dapper.NET:变量名应该与参数名相同吗

  • 本文关键字:参数 NET 变量名 Dapper dapper
  • 更新时间 :
  • 英文 :


我使用Dapper.NET,变量名应该与参数名相同吗?例如:

int id = 123;
string name = "abc";
connection.Execute("insert [KeyLookup](Id, Name) values(@id, @name)",
new { id, name });

这很好用。但是如果我有不同名称的参数该怎么办:

int user_id = 123;
string user_name = "abc";
connection.Execute("insert [KeyLookup](Id, Name) values(@id, @name)",
new { user_id, user_name }); // -?

然后您只需替换参数对象中的名称:

int user_id = 123;
string user_name = "abc";
connection.Execute("insert [KeyLookup](Id, Name) values(@id, @name)",
new { id = user_id, name = user_name }); // -?

最新更新