Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required. Paperback excluded.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
ASP.NET Core 2 Fundamentals

You're reading from   ASP.NET Core 2 Fundamentals Build cross-platform apps and dynamic web services with this server-side web application framework

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher
ISBN-13 9781789538915
Length 298 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Onur Gumus Onur Gumus
Author Profile Icon Onur Gumus
Onur Gumus
Mugilan T. S. Ragupathi Mugilan T. S. Ragupathi
Author Profile Icon Mugilan T. S. Ragupathi
Mugilan T. S. Ragupathi
Arrow right icon
View More author details
Toc

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:

  1. Just right-click on dependencies and select Manage NuGet Packages.
  2. Afterwards write Microsoft.EntityFramework.Core.SqlServer in the search box and install it.

Your screen should look as follows:

  1. Similarly, install the Microsot.EntityFrameworkCore.Tools package, as follows:

So, your project folder for Infrastructure looks as follows:

  1. Next, we create the EF folder in the Infrastructure project and implement our DbContext with a class called RestBuyContext. Make sure you have a reference to the RestBuy project from Infrastructure. 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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime