2017-03-31 40 views
9

我有一個數據庫和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

回答

8

請看看我在GitHub上最近上傳了一個項目 - https://github.com/giorgos07/Daarto這正是你需要的。

+1

謝謝。這真的很有幫助! – Javier

+0

你絕對的傳奇。謝謝! – Nick

+0

你碰巧有Core 2.0的版本嗎?我一直在試圖找到一個例子,但沒有運氣。試圖用Dapper + AspNet Core Identity 2.0創建一個基本項目 – Bojan