ORM 2
ORM 2
(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.
.
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
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
● Context class
● Entity class
● Scalar property
● Navigation property
● DbSet
● How to update entity