如何使用ASP.Net核心身份的短小精灵?

问题描述:

我有一个数据库和iam试图使用核心身份的矮胖来查询数据库。但我坚持在这一点上。我使用的是用户从identityUser的接口:如何使用ASP.Net核心身份的短小精灵?

public class User : IdentityUser 
{ 

} 

的一个制作自定义用户商店CRUD用短小精悍。

public class UserStore : IUserStore<User> 
{ 
    private readonly string connectionString; 

    public UserStore(IConfiguration configuration) 
    { 
     connectionString = configuration.GetValue<string>("DBInfo:ConnectionString"); 
    } 

    internal IDbConnection Connection 
    { 
     get 
     { 
      return new SqlConnection(connectionString); 
     } 
    } 
    public Task<IdentityResult> CreateAsync(User user, CancellationToken cancellationToken) 
    { 
**// HOW TO I RETURN A USER WITH DAPPER HERE?** 
    } 

    public Task<IdentityResult> DeleteAsync(User user, CancellationToken cancellationToken) 
    { 
     throw new NotImplementedException(); 
    } 

    public void Dispose() 
    { 
     throw new NotImplementedException(); 
    } 

    public Task<User> FindByIdAsync(string userId, CancellationToken cancellationToken) 
    { 
     throw new NotImplementedException(); 
    } 

    public Task<User> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken) 
    { 
     throw new NotImplementedException(); 
    } 

    public Task<string> GetUserIdAsync(User user, CancellationToken cancellationToken) 
    { 
     throw new NotImplementedException(); 
    } 

    public Task<string> GetUserNameAsync(User user, CancellationToken cancellationToken) 
    { 
     throw new NotImplementedException(); 
    } 

    public Task<IdentityResult> UpdateAsync(User user, CancellationToken cancellationToken) 
    { 
     throw new NotImplementedException(); 
    } 

谢谢!

+0

我建议你阅读文档:https://github.com/StackExchange/Dapper它基本上是'SqlConnection' /'IDbConnection'上的扩展库。 –

+1

你究竟在问什么?如何根据我们尚未见过的数据库结构编写创建逻辑?这个问题太不清楚,而且答案太广泛。 –

+0

'公共任务 CreateAsync(用户用户,CancellationToken cancellationToken) { ** //如何在此返回用户?** }' – Javier

请看看我在GitHub上最近上传了一个项目 - https://github.com/giorgos07/Daarto这正是你需要的。

+1

谢谢。这真的很有帮助! – Javier

+0

你绝对的传奇。谢谢! – Nick

+0

你碰巧有Core 2.0的版本吗?我一直在试图找到一个例子,但没有运气。试图用Dapper + AspNet Core Identity 2.0创建一个基本项目 – Bojan

你有没有看看Identity.Dapper

+0

是的,谢谢,它帮助了很多! – Javier