0
我試圖轉換一個方法來使用Dapper存儲過程。但我有什麼事情與var result =...
C#從方法中刪除SQL並使用存儲過程和Dapper
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());
}
}
你有問題嗎?它是什麼? –