Entity Framework 7 with .net core 1

Today i am in mode to write ef 7 with code first with .NET core application.
1.First install .net framework 4.6.2 or latest from Microsoft official site .

2.Check install by writing dotnet in cmd.
it will show


Microsoft .NET Core Shared Framework HostVersion : 1.0.1
Build : cee57bf6c981237d80aa1631cfe83cb9ba329f12
.....

3.create a folder dotnetCore and write cd dotnetCore in cmd and then

i.dotnet new
ii.dotnet restore
iii.dotnet run

you will see Hello World! in console.

There you go ..You have created a first project in dot net core with cmd .Will drive into Sql Server with EF 7 code first now.

4.You have see two file i.Program.cs and ii.project.json in your directory.
the file project.json with contain all my dependencies .

Write your json file like this

and Program.cs file like

if every thing is all right ..

Then wirte this three line of code

dotnet restore

dotnet ef migrations add MyMigration

dotnet ef database update

dotnet run.

It will insert database with table Blogs.

5.If you want to add a column name

public string BlogName { get; set; }

then run this command

dotnet ef migrations add MyAddedNewMigration
dotnet ef database update

you will see new column is added to database in table Blogs

Leave a Reply

Your email address will not be published. Required fields are marked *