0% found this document useful (0 votes)
13 views

ORM 2

This document provides a step-by-step guide on installing Entity Framework 6 via NuGet in Visual Studio and setting up a relational database using SQL Server Management Studio. It explains the Database First approach with Entity Framework, detailing how to create an Entity Data Model from an existing database and the components involved, such as storage, conceptual models, and mapping information. Additionally, it covers updating the model when the database changes and key concepts like context class, entity class, and DbSet.

Uploaded by

bperson534
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

ORM 2

This document provides a step-by-step guide on installing Entity Framework 6 via NuGet in Visual Studio and setting up a relational database using SQL Server Management Studio. It explains the Database First approach with Entity Framework, detailing how to create an Entity Data Model from an existing database and the components involved, such as storage, conceptual models, and mapping information. Additionally, it covers updating the model when the database changes and key concepts like context class, entity class, and DbSet.

Uploaded by

bperson534
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Object Relational Mapping

(ORM)
Lecture 02
Install Entity Framework 6 VIA NUGET
● Open Visual Studio: Launch Visual Studio on your computer.
● Create a New Project: Click on "Create a new project" or "File" > "New" > "Project" to create a new project.
● Choose Console Application (Console App (.NET Framework)", not the "Console App") and language as C# (.NET Framework should
be 4.5 or more to work with Entity Framework )
● Name Your Project and Solution: Give your project a name and choose the location where you want to save it. Click "Create" to
create the project.
● Open NuGet Package Manager: Once your project is created, go to "Tools" > "NuGet Package Manager" > "Manage NuGet
Packages for Solution...".
● Search for Entity Framework: In the NuGet Package Manager window, click on the "Browse" tab. Then, search for "EntityFramework"
in the search bar.
● Select EntityFramework Package: Once you find the EntityFramework package in the search results, select it by clicking on it.
● Install EntityFramework: Click on the "Install" button to install Entity Framework into your project.

* You should need to install the following packages from NuGet:


Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
Install a Relational Database
● Download Download SQL Server Management Studio (SSMS)
https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-
studio-ssms?view=sql-server-ver16
● Install Microsoft.SqlServer.Server to visual studio as well via NUGET
● Connect to localhost
Database First Approach with E.F. 6
How to create Entity Framework with existing database?

1. First, Create a Database with following details.

.
2. Add Entity data model (conceptual model used to describe the structure of data, typically
within a relational database, in terms of entities and their relationships. It is a part of the ADO.NET Entity
Framework, a popular Object-Relational Mapping (ORM) framework provided by Microsoft for .NET

applications. )
● Go to Menu Project > Add New Item (Or right click on your project and add new
item) > ADO.NET Entity Data Model > Specify Modal Name as Location > Add
Database first > New connection > set properties > Test connection > ok
Checkbox should select > Discuss the why? > Finish
Entity names : City & Area (are in singular form)
You can see References of Entity framework
is added to your project

If you want to see the content in xml format >


right click on .edmx file > Open with >
XML(Text) Editor
Three parts :

Storage Model :
Contains database
related things (Areas,
Cities)

Conceptual Model :
Contains Domain class
(Area, City)

Mapping information :
How entity get mapped
to your tables
ex:
<EntitySetMapping
Name="Areas">
<EntityTypeMapping
TypeName="ORMDbModel.Area"
>
Model Browser
Right click on project designer > Open Model Browser > Has three parts
Right click on City diagram > Table mapping
Lets’ see the code of Entity classes and domain classes

Go to Solution Explorer > Location.edmx> Location.Context > Location.context.cs


Method OnModelCreating
POCO (Plain Old CLR) Entity class
Let’s see what happened when database changed ?
Right click on the model and > Update Model from Database > Finish > Pincode
property get added > check Area entity class > Save model and recheck Area
entity again
What covers in this Lecture ?

● Context class
● Entity class
● Scalar property
● Navigation property
● DbSet
● How to update entity

You might also like