我最近一直在運行我的API的Dapper擴展庫。下面的代碼返回用戶提供基於單個用戶ID的resptive地址的列表:.NET Dapper範圍
public User GetUserBicProfiles(string userId)
{
using (
var multipleResults = this.db.QueryMultiple("sp_UserPermisisons", new {userId =
userId},commandType: CommandType.StoredProcedure))
{
var user = multipleResults.Read<User>().SingleOrDefault();
var permissions= multipleResults.Read<Permissions>().ToList();
if (user != null&& permissions != null)
{
user.Permissions.AddRange(permissions);
}
return user;
}
}
這個完美的作品,但是當我嘗試使用同一組的細節,但沒有用戶id作爲參數(應該返回所有用戶使用各自的權限),我得到一個與添加範圍有關的錯誤。
System.Collections.Generic.List'不包含'UserPermissions'的定義,也沒有找到接受類型'System.Collections.Generic.List'的第一個參數的擴展方法'UserPermissions' ?using指令或程序集引用)
返回所有的方法是:
public List<User> GetUsers()
{
using (var multipleResults = this.db.QueryMultiple("sp_UserPermissions",commandType: CommandType.StoredProcedure))
{
var user = multipleResults.Read<User>().ToList();
var permissions = multipleResults.Read<Permissions>().ToList();
if (user != null && permissions != null)
{
user.Permissions.AddRange(permissions);
}
return user;
}
}
User類是:
public class User
{
public User()
{
this.Permissions = new List<Permissions>();
}
public string UserId { get; set; }
public string UserName { get; set; }
public string ApplicationName { get; set; }
public string Email { get; set; }
public string Comment { get; set; }
public string Password { get; set; }
public string PasswordQuestion { get; set; }
public string PasswordAnswer { get; set; }
public bool? IsApproved { get; set; }
public DateTime LastActivityDate { get; set; }
public DateTime LastLoginDate { get; set; }
public DateTime LastPasswordChangeDate { get; set; }
public DateTime CreationDate { get; set; }
public bool? IsOnline { get; set; }
public bool? IsLockedOut { get; set; }
public DateTime LastLockedOutDate { get; set; }
public bool? FailedPasswordAttempCount { get; set; }
public DateTime FailedPasswordAttemptWithStart { get; set; }
public bool? FailedPasswordAnswerAttemptCount { get; set; }
public DateTime FailedPasswordAnsdwerAttemptWindowStart { get; set; }
public List<Permissions> Permissions { get; set; }
}
確實,如果沒有用戶id傳入的存儲過程將返回的東西。 – ChrisBint
沒有所謂的'UserPermissions'類成員,類怎麼過MBR稱爲'Permissions'存在 – rt2800
修正UserPermissions,應在被權限。 – CSharpNewBee