Short answer: to create an ADO.NET Entity Data Model in an ASP.NET MVC project, right-click the Models folder, choose Add > New Item > Data > ADO.NET Entity Data Model, pick EF Designer from database, select your SQL Server database and tables, and finish the wizard. Visual Studio creates an .edmx file, a DbContext class, and one entity class per table.
In this guide you'll build a small Codingvila Store sample: two SQL Server tables, an .edmx model generated from them, and an MVC page that lists recent orders. Along the way you'll see what each generated file does, how to update the model after a schema change, and how to fix the errors beginners hit most often.
This tutorial uses Entity Framework 6 (EF6) in an ASP.NET MVC 5 project on .NET Framework. EF6 is in maintenance mode, which means Microsoft still fixes security issues but isn't adding features (see the EF6 repository). For a new project on modern .NET, EF Core is the recommended choice, and it doesn't support the visual designer or .edmx files.
The diagram below shows the whole flow. The wizard reads your database, writes an .edmx file, generates C# classes from it, and your controller then queries those classes.
Prerequisites
- Visual Studio with the ASP.NET and web development workload, so you can create an ASP.NET Web Application (.NET Framework) with the MVC template.
- The Entity Framework 6 Tools component. It's included in the Data storage and processing workload, or you can add it as an individual component. See the Entity Data Model tools documentation. Installing the EF runtime package alone does not give you the designer.
- SQL Server, SQL Server Express, or LocalDB, and an account that can read the objects you want to import.
- Basic C# and a rough idea of what an MVC controller and view do.
What the EDMX file represents
Entity Framework is an object-relational mapper (ORM). It maps rows in your tables to C# objects so you can work with data using LINQ instead of hand-written SQL.
In the designer workflow, the .edmx file is an XML file that holds three things: a conceptual model (your entities), a storage model (your tables), and the mapping between them. Visual Studio then runs T4 templates (.tt files) against the model to generate a DbContext class and one plain C# class per entity. Microsoft's EF6 Database First walkthrough covers the same process.
Step 1: Create the sample database
Run this script in SQL Server Management Studio. Both tables have primary keys on purpose. Without a primary key, the designer can't treat a table as a normal editable entity.
CREATE DATABASE CodingvilaStore;
GO
USE CodingvilaStore;
GO
CREATE TABLE dbo.Customers (
CustomerId INT IDENTITY(1,1) NOT NULL CONSTRAINT PK_Customers PRIMARY KEY,
FullName NVARCHAR(100) NOT NULL,
Email NVARCHAR(150) NOT NULL
);
CREATE TABLE dbo.Orders (
OrderId INT IDENTITY(1,1) NOT NULL CONSTRAINT PK_Orders PRIMARY KEY,
CustomerId INT NOT NULL CONSTRAINT FK_Orders_Customers REFERENCES dbo.Customers (CustomerId),
OrderDate DATETIME2(0) NOT NULL,
TotalAmount DECIMAL(10, 2) NOT NULL
);
INSERT INTO dbo.Customers (FullName, Email) VALUES
(N'Ava Thompson', N'ava.thompson@example.com'),
(N'Liam Carter', N'liam.carter@example.com');
INSERT INTO dbo.Orders (CustomerId, OrderDate, TotalAmount) VALUES
(1, '2026-09-03', 89.50),
(2, '2026-09-18', 120.00),
(1, '2026-10-05', 45.25);
Expected result: SQL Server reports that the rows were inserted, and the database now has two tables linked by a foreign key.
Step 2: Create the model from the existing database
- Create an ASP.NET Web Application (.NET Framework) with the MVC template. This example uses the project name
Codingvila.Store. - Right-click the
Modelsfolder and choose Add > New Item. Select Data, then ADO.NET Entity Data Model, and name itCodingvilaStoreModel. - Choose the database-first option. Current EF6 tooling calls it EF Designer from database; older versions call it Generate from database. The other options (Empty EF Designer model, Empty Code First model and Code First from database) are different workflows.
- Select New Connection, choose Microsoft SQL Server, and enter the server, authentication method and database name (
CodingvilaStore). If you use SQL Server authentication, choose the option that excludes sensitive data from the connection string, and supply the password through your own configuration. Never commit a real password to source control. - Keep the suggested name,
CodingvilaStoreEntities, for saving the connection settings inWeb.config. If prompted for the Entity Framework version, choose Entity Framework 6.x. - Expand Tables > dbo and tick
CustomersandOrders. Leave Pluralize or singularize generated object names and Include foreign key columns in the model ticked, then click Finish. - If Visual Studio warns that running a T4 template could harm your computer, click OK. These are the EF templates in your own project. Only accept this prompt for templates you trust.
Expected result: the designer opens and shows Customer and Order boxes joined by an association line. In Solution Explorer, expand CodingvilaStoreModel.edmx to find CodingvilaStoreModel.Context.tt (which generates the context class) and CodingvilaStoreModel.tt (which generates Customer.cs and Order.cs).
Check the generated connection string
The wizard adds an entry like the one below to Web.config. An Entity Framework connection string has three parts: the metadata paths to the model, the provider, and an ordinary SQL Server connection string inside the quotes. The " sequences are just escaped double quotes.
<connectionStrings>
<add name="CodingvilaStoreEntities"
connectionString="metadata=res://*/Models.CodingvilaStoreModel.csdl|res://*/Models.CodingvilaStoreModel.ssdl|res://*/Models.CodingvilaStoreModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(localdb)\MSSQLLocalDB;initial catalog=CodingvilaStore;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
Your data source will differ. The name must match the one passed to the generated context, which is the next step.
Look at the generated context class
Open CodingvilaStoreModel.Context.cs. Typical EF6 output looks like this:
namespace Codingvila.Store.Models
{
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class CodingvilaStoreEntities : DbContext
{
public CodingvilaStoreEntities()
: base("name=CodingvilaStoreEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<Customer> Customers { get; set; }
public virtual DbSet<Order> Orders { get; set; }
}
}
Here's what each part does:
base("name=CodingvilaStoreEntities")tells EF whichWeb.configconnection string to use.DbSet<T>properties are your entry points to each table.CustomersandOrdersare what you query.OnModelCreatingthrowsUnintentionalCodeFirstExceptionon purpose. It's a guard that fires if EF can't load the.edmxand starts falling back to Code First conventions.
Don't edit the generated .cs files. Visual Studio rewrites them whenever the model changes, and your edits will be lost. Extend the classes through separate partial class files instead.
Display the data in an MVC page
Now use the model. Start with a view model in the Models folder. It exposes only the four values the page needs, not the full entities.
using System;
namespace Codingvila.Store.Models
{
public class OrderRowViewModel
{
public int OrderId { get; set; }
public string CustomerName { get; set; }
public DateTime OrderDate { get; set; }
public decimal TotalAmount { get; set; }
}
}
Next, add OrdersController.cs to the Controllers folder:
using System.Data.Entity;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Mvc;
using Codingvila.Store.Models;
namespace Codingvila.Store.Controllers
{
public class OrdersController : Controller
{
private readonly CodingvilaStoreEntities _db = new CodingvilaStoreEntities();
// GET: /Orders
public async Task<ActionResult> Index()
{
var orders = await _db.Orders
.OrderByDescending(o => o.OrderDate)
.Take(50)
.Select(o => new OrderRowViewModel
{
OrderId = o.OrderId,
CustomerName = o.Customer.FullName,
OrderDate = o.OrderDate,
TotalAmount = o.TotalAmount
})
.ToListAsync();
return View(orders);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_db.Dispose();
}
base.Dispose(disposing);
}
}
}
This controller does four things worth noticing:
- It creates one context per controller instance. MVC creates a new controller for each request, so each request gets its own context.
- It disposes the context in
Dispose, which releases the database connection. - It sorts, limits to 50 rows, and projects into the view model in the database query. Only the needed columns come back.
- It uses
ToListAsync()fromSystem.Data.Entityso the request thread isn't blocked while SQL Server responds.
Create Views/Orders/Index.cshtml:
@model IEnumerable<Codingvila.Store.Models.OrderRowViewModel>
@{
ViewBag.Title = "Recent orders";
}
<h2>Recent orders</h2>
<table class="table">
<thead>
<tr><th>Order</th><th>Customer</th><th>Date</th><th>Total</th></tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@item.OrderId</td>
<td>@item.CustomerName</td>
<td>@item.OrderDate.ToString("MMM d, yyyy")</td>
<td>@item.TotalAmount.ToString("C")</td>
</tr>
}
</tbody>
</table>
Razor HTML-encodes @item.CustomerName automatically, which protects the page from script injection through database values. Build the project, run it, and go to /Orders. With the sample data you should see the rows below. Date and currency formats follow the server's culture, and these samples assume US English.
| Order | Customer | Date | Total |
|---|---|---|---|
| 3 | Ava Thompson | Oct 5, 2026 | $45.25 |
| 2 | Liam Carter | Sep 18, 2026 | $120.00 |
| 1 | Ava Thompson | Sep 3, 2026 | $89.50 |
If you want to export data like this, see how to export data to CSV in ASP.NET MVC using Entity Framework.
Verify and maintain the model
Build the project and confirm the connection string name matches the one in the generated context. Run a read against a development database, as you did above, before wiring the context into more controllers.
When the database schema changes, open the .edmx designer, right-click an empty area, and choose Update Model from Database. The Add tab imports new objects, Refresh syncs changed ones, and Delete lists objects that no longer exist. Save the model so the templates regenerate the classes. Commit your work to source control first so you can review the generated changes and revert a bad update.
If the ADO.NET Entity Data Model item is missing
First check the project type and target framework. The EF6 designer works with .NET Framework projects. Then open the Visual Studio Installer, choose Modify, and confirm that Entity Framework 6 Tools is ticked under Individual components. Adding an .edmx to a .NET 6 or later project can also fail with a message that the EF runtime assemblies aren't installed.
An ASP.NET Core project should follow EF Core reverse engineering, which generates entity classes and a DbContext with Scaffold-DbContext or dotnet ef dbcontext scaffold.
Common errors and how to fix them
- A table is missing or can't be edited. It probably has no primary key. Add one in SQL Server, then run Update Model from Database.
- "No connection string named ... could be found." This usually happens when the
.edmxlives in a class library. Copy the connection string into theWeb.configof the MVC project that runs the app. - "Unable to load the specified metadata resource." The
metadata=res://*/...paths no longer match the model, often after renaming or moving the.edmx. Fix the paths, or delete the connection string and re-run the wizard. UnintentionalCodeFirstException. EF couldn't load the model, usually because the connection string is missing or its name doesn't match the one passed tobase(...).- Edits to a generated class disappear. The T4 templates overwrite them. Use a separate
partial classfile.
EDMX, Code First from database, and EF Core
| Approach | Where the model lives | Visual designer |
|---|---|---|
| EF6 EF Designer from database | In an .edmx XML file; classes come from T4 templates | Yes |
| EF6 Code First from database | In plain C# classes you can edit | No |
| EF Core | In C# classes and a DbContext | No; .edmx isn't supported |
Quick answers
What is an .edmx file?
It's the XML file that stores the conceptual model, storage model and mapping for an Entity Data Model, and the designer edits it visually.
Is Entity Framework 6 still supported?
Yes, it's in maintenance mode. Microsoft fixes security issues but isn't adding features.
Can I use an EDMX file with EF Core?
No. EF Core has no visual designer and doesn't support .edmx files. Use reverse engineering instead.
Key takeaways
- Use EF Designer from database in a .NET Framework MVC project with the EF6 Tools installed.
- The result is an
.edmxfile, aDbContextand one class per table. Don't edit the generated files; extend them with partial classes. - Give every table a primary key, and keep passwords out of source control.
- Use Update Model from Database after schema changes, and review the result before rebuilding.
- For new projects on modern .NET, use EF Core instead.
Related tutorials
To keep building on this model, learn how to export data to a CSV file in ASP.NET MVC, or see the Entity Framework CSV export example.

