【发布时间】:2016-10-22 02:12:52
【问题描述】:
我正在尝试将一种方法转换为使用 Dapper 的存储过程。但我对var result =... 发生的事情感到很困惑
public Task<TUser> FindByIdAsync(Guid userId)
{
var sql = @"SELECT *
FROM IdentityUser
WHERE UserId = @USERID";
using (var connection = new SqlConnection(_connection))
{
var result = connection.Query<TUser, IdentityProfile, TUser>(sql, (user, profile) => { user.Profile = profile;
return user; },
new { userId }, splitOn: "UserId").SingleOrDefault();
return Task.FromResult(result);
}
}
这是我所拥有的:
public Task<TUser> FindByIdAsync(Guid userId)
{
using (var connection = new SqlConnection(_connection))
{
var param = new DynamicParameters();
param.Add("@UserId", userId);
return Task.FromResult(connection.Query("IdentityGetUserById", param, commandType: CommandType.StoredProcedure).SingleOrDefault());
}
}
【问题讨论】:
-
您有问题吗?这是什么?
标签: c# asp.net sql-server stored-procedures dapper