C#. Entity. CodeSecondApproach

If db already exists and filled with data we just can create Entities in code…

For example lets create db manually… in localdb of SQL Server

View->Server Explorer.

Connect to Database in Visual Studio

Next in serverName type “(localdb)\MSSQLLocalDB” for vs 2015 and choose new datebase or type new one and vs will suggest create new one

Next lets get connection string of our new db in localdb

Now put connection string to app.config

Now create new table

and add columns

Click Update and see

Update DataBase and start Editing some data

Now SolutionExplorer > Manage NuGetPackages for Solution > type Entity in search box and Install it to your project

Добавление Entity Framework через NuGet

Установка Entity Framework

Add using System.Data.Entity if not added before…

Lets write user class and userContext class

In main lets check what is in our dataBase

Full code is

 

 

 

 

This entry was posted in C#. Bookmark the permalink.