O/RM in .NET Core
- Object-relational mapper (O/RM)
- Supports many different DB providers (list)
examples:- MS SQL Server
- SQLite
- PostgreSQL
- MySQL
- In-Memory (for testing)
- Latest version: EF Core 3.0
- NuGet (example): Microsoft.EntityFrameworkCore.SqlServer
- Follow installing docs to add EF to project
- Make sure to install global EF tools:
dotnet tool install --global dotnet-ef
- Make sure to install global EF tools:
- Work through tutorials in EF docs
- Tips:
- Run local SQL Server using Docker:
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -e 'MSSQL_PID=Express' -p 1433:1433 -d mcr.microsoft.com/mssql/server
- Install and use free SQL Server Developer Edition or SQL Server 2017 Express LocalDB
- Use In-Memory DB for simple test scenarios
- Run local SQL Server using Docker:
<!--#include file="entity-framework/0010-intro/Person.cs" -->
- Read more about creating a Model
<!--#include file="entity-framework/0010-intro/Context.cs" -->
<!--#include file="entity-framework/0010-intro/WriteToDB.cs" -->
- Read more about writing data
<!--#include file="entity-framework/0030-joins/AddingWithJoin.cs" -->
- Note single call to
Add
andSaveChangesAsync
<!--#include file="entity-framework/0010-intro/ReadFromDB.cs" -->
- Read more about querying data
<!--#include file="entity-framework/0030-joins/QueryWithJoin.cs" -->
Include
: GettingOrder
with relatedCustomer
- Address Book example on GitHub
AddJsonOptions
in Startup.cs for handling loops in JSON serializationservices.AddDbContext
in Startup.cs for adding EF context to ASP.NET Core Dependency Injection- AutoMapper in Startup.cs
- Migrations
- Visual Studio Scaffolding for controllers
- EF's
Include
in GroupsController.cs
- Readings
- Videos
- Want to know more details? Watch Entity Framework Core on Channel 9
- Exercises