Entity Framework V2
Entity Framework V2
#
Entity Framework
Desktop Application
Learning Outcomes
01 02
ORM EF Overview
03 04
Reading Data with CRUD Operations
EF by EF
ADO .Net
2
In this method to deal with database
3
we needed to:
1. Open a connection between VS
4 project and SQLServer and certain
the database.
2. Write the query string.
3. Assign the query result to an
adapter.
4. Make a data table to fill the
records in it then map it into
DataGrid.
Is there an easier way?
0
ORM 1
ORM
Object–relational mapping (ORM, O/RM, and O/R mapping tool) in computer
science is a programming technique for converting data between a relational
database and the heap of an object-oriented programming language. This creates,
in effect, a virtual object database that can be used from within the programming
language.
0
EF Overview2
EF Overview
➢ Entity Framework is an open-source ORM framework for .NET applications
supported by Microsoft.
➢ It enables developers to work with data using objects of domain specific
classes without focusing on the underlying database tables and columns
where this data is stored.
➢ With the Entity Framework, developers can work at a higher level of
abstraction when they deal with data, and can create and maintain data-
oriented applications with less code compared with traditional applications.
Right click on
ExpenseIt
project
Reading Data with EF
Select Data
Name the
Model
Reading Data with EF
Choose EF Designer
from database to create
a model based on an
existing database.
Reading Data with EF
Reading Data with EF
Reading Data with EF
Reading Data with EF
Make sure to
select the
database
tables
Reading Data with EF
Mapping the
database table into
the Visual Studio
project
Reading Data with EF
In the ExpenseReportPage
constructor:
1. we will comment the call of
showTheReport() method
which is used ADO.NET way.
2. Call showByEntity() method
which we will create.
Reading Data with EF
Create
ExpenseEntities
object (db) which
represents the
database
In the first line we will get values from column Department where
column Names == _person.Name, But if we bind the result directly
with the label it will cause a logical error.
Because where get multiple records and we want to assign these
records to a label content which should has a single value.
So we assigned the result to rec variable then bind the label content
with it using FirstOrDefault() method.
FirstOrDefault() get one record only which is the first one.
Output…
IMAGE
0
CRUD 1
Operations by
EF
CRUD Operations by EF
At first we will create a Modify page like this
15
minutes
Activity
Add Record
To add record we should
handle this operation in the
code behind by creating a
method that should execute
whenever we click on Add
button.
Create a method with
CRUD Operations by EF name AddRecord
Update Record
To update record we should
handle this operation in the
code behind by creating a
method that should execute
whenever we determine the
ID and click on the Update
button
Create a method with
CRUD Operations by EF name UpdateRecord
1. Create an object
with
ExpenseReport
type
To update the
result use
AddOrUpdate()
method
Let’s try to update a record
CRUD Operations by EF
Delete Record
To update record we should
handle this operation in the
code behind by creating a
method that should execute
whenever we determine the
ID and click on the Delete
button
CRUD Operations by EF
IMAGE
THANK YOU!