Featured Article

ASP.NET Core Identity Without Entity Framework Custom Implementation Guide

Kenneth Jul 13, 2026

Asp.Net Core Identity, a powerful and flexible user management system, is not inherently tied to Entity Framework. While Entity Framework is a common choice for data access, Asp.Net Core Identity offers other options. Let's delve into how to employ Asp.Net Core Identity without Entity Framework, focusing on data stores like Dapper and raw SQL.

What is the difference between ASP.NET and ASP.NET Core?
What is the difference between ASP.NET and ASP.NET Core?

Before we head into the implementation, understanding why one might choose not to use Entity Framework is essential. Some developers prefer the fine-grained control offered by raw SQL or ORMs like Dapper, while others have pre-existing data schemas that aren't compatible with Entity Framework. Whatever the reason, this guide will walk you through the process.

๐—”๐—ฟ๐—ฒ ๐˜†๐—ผ๐˜‚ ๐˜€๐˜๐—ฟ๐˜‚๐—ด๐—ด๐—น๐—ถ๐—ป๐—ด ๐˜„๐—ถ๐˜๐—ต ๐—”๐˜‚๐˜๐—ต๐—ฒ๐—ป๐˜๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ฎ๐—ป๐—ฑ ๐—”๐˜‚๐˜๐—ต๐—ผ๐—ฟ๐—ถ๐˜‡๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ถ๐—ป ๐—”๐—ฆ๐—ฃ .๐—ก๐—˜๐—ง ๐—–๐—ผ๐—ฟ๐—ฒ? This guide helped a lot of developers Securing yourโ€ฆ | Anton Martyniuk | 41 comments
๐—”๐—ฟ๐—ฒ ๐˜†๐—ผ๐˜‚ ๐˜€๐˜๐—ฟ๐˜‚๐—ด๐—ด๐—น๐—ถ๐—ป๐—ด ๐˜„๐—ถ๐˜๐—ต ๐—”๐˜‚๐˜๐—ต๐—ฒ๐—ป๐˜๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ฎ๐—ป๐—ฑ ๐—”๐˜‚๐˜๐—ต๐—ผ๐—ฟ๐—ถ๐˜‡๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ถ๐—ป ๐—”๐—ฆ๐—ฃ .๐—ก๐—˜๐—ง ๐—–๐—ผ๐—ฟ๐—ฒ? This guide helped a lot of developers Securing yourโ€ฆ | Anton Martyniuk | 41 comments

Setting up Asp.Net Core Identity with Dapper

Dapper, a popular micro-ORM, is a lightweight alternative to heavier ORMs like Entity Framework. It offers more control over SQL queries and can lead to better performance in certain scenarios.

a woman's face is surrounded by blue and green digital art pieces on a black background
a woman's face is surrounded by blue and green digital art pieces on a black background

First, install the Dapper package via NuGet: `Install-Package Dapper`. Then, create data models for your user and role entities. Unlike Entity Framework, you'll need to manage the DbContext and database connection yourself.

Configuring Dapper and the Database Connection

Data Access in ASP.NET Core using EF Core (Code First)
Data Access in ASP.NET Core using EF Core (Code First)

In your startup.cs file, configure Dapper to use your chosen database (SQL Server, MySQL, PostgreSQL, etc.). This involves creating a connection string and passing it to Dapper's `OpenorescentId` connection string naming convention.

Next, create a connection and pass it to Dapper. Here's a sample of how you might set this up:

```csharp using (var connection = new SqlConnection("your_connection_string")) { connection.Execute("CREATE TABLE IF NOT EXISTS AspNetUsers(...);"); // ... other table creation scripts } ```

Implementing User and Role Management

A Step by Step Guide for ASP.NET Core Configuration
A Step by Step Guide for ASP.NET Core Configuration

Now, create methods for creating, retrieving, updating, and deleting users and roles. With Dapper, you'll write raw SQL queries and manage the resulting data yourself. For instance, here's how you might create a user:

```csharp public async Task CreateUserAsync(User user, string password) { // Hash the password var hashedPassword = new PasswordHasher().HashPassword(user, password); // Insert the user into the database using (var connection = new SqlConnection("your_connection_string")) { await connection.ExecuteAsync( "INSERT INTO AspNetUsers (UserName, PasswordHash, Email, EmailConfirmed, PhoneNumberConfirmed) VALUES (@UserName, @PasswordHash, @Email, @EmailConfirmed, @PhoneNumberConfirmed)", new { UserName = user.UserName, PasswordHash = hashedPassword, Email = user.Email, EmailConfirmed = user.EmailConfirmed, PhoneNumberConfirmed = user.PhoneNumberConfirmed } ); } return IdentityResult.Success; } ```

Using Asp.Net Core Identity with Raw SQL

For more control over your database operations, you can use raw SQL with Asp.Net Core Identity.

Introduction to Entity Framework Core - The Engineering Projects
Introduction to Entity Framework Core - The Engineering Projects

Raw SQL usage is similar to Dapper, but you'll interact directly with your database using ADO.NET. This approach offers maximal control but requires more setup and management of database transactions.

Implementing Database Operations with Raw SQL

Self-Identity Planner for Personal Growth and Digital Identity Exploration
Self-Identity Planner for Personal Growth and Digital Identity Exploration
List of the top identity and access management (IAM) certifications
List of the top identity and access management (IAM) certifications
Code First Approach in Entity Framework in Asp.net MVC with Example - Tutlane
Code First Approach in Entity Framework in Asp.net MVC with Example - Tutlane
an ad with the words identity and access management in black letters on it, along with other
an ad with the words identity and access management in black letters on it, along with other
Creative Dark Coding Wallpaper, Black And White Coding Art, Cyberpunk Wallpaper Black And White, Black And White Cybersecurity Art, Black And White Crypto Art, Futuristic Dystopian Poster Design, Futuristic Dystopia Prints, Ascii Art Vandalism Wallpaper, Futuristic Jesus
Creative Dark Coding Wallpaper, Black And White Coding Art, Cyberpunk Wallpaper Black And White, Black And White Cybersecurity Art, Black And White Crypto Art, Futuristic Dystopian Poster Design, Futuristic Dystopia Prints, Ascii Art Vandalism Wallpaper, Futuristic Jesus
Middle Name, Jesus Images, First Names, Jesus
Middle Name, Jesus Images, First Names, Jesus
Post by @im-a-developer ยท 1 image
Post by @im-a-developer ยท 1 image
Ceylinco E - Motor Card
Ceylinco E - Motor Card
Dark Backgrounds, Woman Face, Focal Point, Light And Shadow, Close Up, Drawings, Manga
Dark Backgrounds, Woman Face, Focal Point, Light And Shadow, Close Up, Drawings, Manga

To create a user with raw SQL, you'd write a similar query to the one used with Dapper. However, you'd manage the transaction and connection yourself, ensuring proper handling of database resources.

Here's a basic example:

```csharp public async Task CreateUserAsync(User user, string password) { var hashedPassword = new PasswordHasher().HashPassword(user, password); using (var connection = new SqlConnection("your_connection_string")) using (var transaction = connection.BeginTransaction()) { await connection.ExecuteAsync( "INSERT INTO AspNetUsers (UserName, PasswordHash, Email, EmailConfirmed, PhoneNumberConfirmed) VALUES (@UserName, @PasswordHash, @Email, @EmailConfirmed, @PhoneNumberConfirmed)", new { UserName = user.UserName, PasswordHash = hashedPassword, Email = user.Email, EmailConfirmed = user.EmailConfirmed, PhoneNumberConfirmed = user.PhoneNumberConfirmed }, transaction ); transaction.Commit(); } return IdentityResult.Success; } ```

In conclusion, Asp.Net Core Identity is flexible and can be used effectively with data access technologies other than Entity Framework. Whether you prefer the simplicity of Dapper or the maximal control of raw SQL, Asp.Net Core Identity can accommodate your preferences. By mastering these approaches, you can expand your toolkit and tackle a wider range of projects.