Create EF Context and Migrations
For starters, we need to install Entity Framework and its tools to our Infrastructure
project.
Follow these steps to create the EF context:
- Just right-click on dependencies and select
Manage NuGet Packages
. - Afterwards write
Microsoft.EntityFramework.Core.SqlServer
in the search box and install it.
Your screen should look as follows:
- Similarly, install the
Microsot.EntityFrameworkCore.Tools
package, as follows:
So, your project folder for Infrastructure
looks as follows:
- Next, we create the
EF
folder in theInfrastructure
project and implement ourDbContext
with a class calledRestBuyContext
. Make sure you have a reference to theRestBuy
project fromInfrastructure.
Use this code:
Note
Go to https://goo.gl/wYLwRA to access the code.
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using RestBuy.Entities; using System; using System.Collections.Generic; using System.Text; ... void ConfigureStockAmount(EntityTypeBuilder<StockAmount...