Featured Article

Build Fast C Web API Without Entity Framework Step By Step Guide

Kenneth Jul 13, 2026

Building a Web API using C# doesn't necessarily require Entity Framework (EF). While EF is a robust ORM (Object-Relational Mapping) tool, it's not the only method to interact with databases in .NET. If you prefer a more manual approach or need to work with databases not supported by EF, you can still create powerful Web APIs with C#.

c# web api without entity framework
c# web api without entity framework

In this guide, we'll explore how to create a C# Web API without using Entity Framework. We'll discuss different approaches to database interaction, including using raw ADO.NET, microORMs like Dapper, or even NoSQL databases like MongoDB with libraries like MongoDB.NET.

Implementing Web APIs: Connect & Fetch Data Like a Pro πŸŒπŸš€
Implementing Web APIs: Connect & Fetch Data Like a Pro πŸŒπŸš€

Alternatives to Entity Framework for Database Interaction

When building a Web API without Entity Framework, you'll need to decide on an alternative for interacting with your database. Here are some popular options:

an image of a website page with dark colors and blue lights on the bottom corner
an image of a website page with dark colors and blue lights on the bottom corner

1. ADO.NET: ADO.NET is a Microsoft data access technology that allows you to connect to and interact with databases. It provides low-level control but can be verbose and error-prone.

ADO.NET in C# Web API

the api gateway framework is shown in this graphic
the api gateway framework is shown in this graphic

To use ADO.NET in your Web API, you'll first need to install the System.Data.SqlClient package. Then, create a connection, command, and data reader to execute your SQL queries and fetch data.

Here's a simple example of selecting data using ADO.NET:

using (SqlConnection conn = new SqlConnection(_connectionString))
{
    using (SqlCommand cmd = new SqlCommand("SELECT * FROM Users", conn))
    {
        conn.Open();
        using (SqlDataReader reader = cmd.ExecuteReader())
        {
            while (reader.Read())
            {
                // Process data
            }
        }
    }
}

MicroORMs: Dapper

the diagram shows how to use api architecture styles for web hosting and application development, as well as
the diagram shows how to use api architecture styles for web hosting and application development, as well as

MicroORMs like Dapper provide a lightweight, simple alternative to full-blown ORMs. Dapper is easy to set up,.Map and highly performant, making it a popular choice for Web APIs.

Dapper uses a fluent interface to map SQL queries to C# methods, allowing for easy data retrieval and operation. To use Dapper, install the Dapper package and prepare your SQL queries as C# methods:

public IEnumerable<User> GetUsers()
{
    return Connection.Query<User>("SELECT * FROM Users").AsList();
}

Working with NoSQL Databases

What is an API? 🐝 Easy Explanation for Beginners | Coding Notes
What is an API? 🐝 Easy Explanation for Beginners | Coding Notes

If you're using a NoSQL database like MongoDB, you can interact with it using libraries like MongoDB.NET. MongoDB provides a flexible schema, high performance, and horizontal scalability.

To use MongoDB.NET, install the MongoDB.Driver package and create an instance of IMongoDatabase to perform CRUD operations:

what is api? - screenshote for application programming and web development in the usa
what is api? - screenshote for application programming and web development in the usa
the screenshot shows different types of apis and how they are used to use them
the screenshot shows different types of apis and how they are used to use them
One framework. Ten types of apps.

Here's the full map.

π–πžπ› π€ππˆπ¬
β†’ The default choice. Minimal APIs or controllers, HTTP + JSON.
β†’ dotnet new webapi
β†’ Best for: public APIs, mobile backends… | Julio Casal | 11 comments
One framework. Ten types of apps. Here's the full map. π–πžπ› π€ππˆπ¬ β†’ The default choice. Minimal APIs or controllers, HTTP + JSON. β†’ dotnet new webapi β†’ Best for: public APIs, mobile backends… | Julio Casal | 11 comments
a web api with asp net core, net 6 0 build a web api with asp net core
a web api with asp net core, net 6 0 build a web api with asp net core
an image of the api security best practices poster with text on it and images of different devices
an image of the api security best practices poster with text on it and images of different devices
the api architecture diagram is shown in black and orange, as well as text that reads api architecture
the api architecture diagram is shown in black and orange, as well as text that reads api architecture
a diagram that shows the types of apis and their use cases
a diagram that shows the types of apis and their use cases
Type-Safe E-Commerce API for Modern Commerce Applications
Type-Safe E-Commerce API for Modern Commerce Applications
Website Development
Website Development

var client = new MongoClient(_connectionString);
var database = client.GetDatabase("myDatabase");
var usersCollection = database.GetCollection<User>("Users");

async Task AddUser(User user)
{
    await usersCollection.InsertOneAsync(user);
}

Document Databases and Web APIs

When working with document databases, your Web API models will align closely with the document structure. This can simplify your API design and make it more intuitive to use. Additionally, NoSQL databases can offer better performance at scale due to their distributed nature.

In conclusion, building a C# Web API without Entity Framework provides flexibility in choosing the right data access strategy for your needs. Whether you prefer low-level control with ADO.NET, simplicity with Dapper, or the flexibility of NoSQL with MongoDB.NET, you have powerful options to create robust and performant Web APIs. Happy coding!