Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use dapper with ASP.Net core Identity?

Tags:

I have a database and iam trying to use dapper with Core Identity to make queries to database. but i am stuck at this point. I am using a User from the interface of identityUser:

public class User : IdentityUser
{

}

The with a making a custom user store for CRUD with dapper.

 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();
    }

thanks!

like image 422
Gonzalo Avatar asked Mar 31 '17 12:03

Gonzalo


People also ask

Does Dapper support .NET core?

If you want to learn how to create migrations and how to seed data with Dapper, you can read our Dapper Migrations with FluentMigrator and ASP.NET Core article. Once we have our table and the data, we can create a new Web API project.

What is Dapper .NET core?

Dapper is a simple Object Mapping Framework or a Micro-ORM that helps us to Map the Data from the Result of an SQL Query to a . NET Class efficiently. It would be as simple as executing a SQL Select Statement using the SQL Client object and returning the result as a Mapped Domain C# Class.

Is Dapper better than Entity Framework?

Dapper is literally much faster than Entity Framework Core considering the fact that there are no bells and whistles in Dapper. It is a straight forward Micro ORM that has minimal features as well. It is always up to the developer to choose between these 2 Awesome Data Access Technologies.


1 Answers

Please take a look at a project that i recently uploaded on GitHub - https://github.com/giorgos07/Daarto It's exactly what you need.

like image 149
Giorgos Manoltzas Avatar answered Sep 22 '22 04:09

Giorgos Manoltzas