我有这个问题:
const string query = @"
select *
from [Users] u
left join [UserRoles] ur
on [ur].[UserId] = [u].[UserId]
left join [Roles] r
on [r].[RoleId] = [ur].[RoleId]
left join [ExternalLogins] el
on [el].[UserId] = [u].[UserId];
";
和下一个类结构:
public sealed class User : IUser<string>
{
public string Id {
get { return this.UserId.ToString(); }
}
public Guid UserId { get; set; }
public string PasswordHash { get; set; }
public string SecurityStamp { get; set; }
public string UserName { get; set; }
public IQueryable<UserLoginInfo> UserLoginInfos;
public IQueryable<Role> Roles;
}
我希望使用单个SQL查询从Dapper获取IEnumerable<User>
(这在开始时)。
var rows = connection.Query(query).ToArray();
if (rows.Length == 0) {
return null;
}
var users = ...
return users;
有什么例子吗?