KEMBAR78
Entity Framework - Part 1 | PDF | Entity Framework | Software
0% found this document useful (0 votes)
11 views30 pages

Entity Framework - Part 1

This document provides an overview of using Entity Framework with Oracle Database in a software engineering lab setting. It covers the prerequisites, steps to create an Oracle connection in Visual Studio, and the process of creating an Entity Data Model. Additionally, it explains how to query data using LINQ to Entities and demonstrates how to fill a ComboBox with data from the database.

Uploaded by

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

Entity Framework - Part 1

This document provides an overview of using Entity Framework with Oracle Database in a software engineering lab setting. It covers the prerequisites, steps to create an Oracle connection in Visual Studio, and the process of creating an Entity Data Model. Additionally, it explains how to query data using LINQ to Entities and demonstrates how to fill a ComboBox with data from the database.

Uploaded by

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

Software Engineering Lab

Oracle Database with


Entity Framework
Part 1

Lab 8
Agenda

 Entity Framework introduction


 Pre-requisites
 Create Oracle Connection in VS
 Creating Entity data model using wizard
 Entity framework data retrieval

2
Entity framework
 Entity Framework is an enhancement to ADO.NET that
gives developers an automated mechanism for accessing
data in database.
 We used Entity framework to generate access classes for
existing database.
 EF creates data access classes for your existing
database, so that you can use these classes to interact
with the database instead of ADO.Net directly.

3
Pre-requisites

 Visual studio
 Oracle 11g database
 Setup the suitable Oracle Data Access
Components (ODAC)
(ODAC setup presentation)

4
5
Working with entity framework in
VS.Net

1. Connect to oracle database from


server explorer
2. Add “Ado.net Entity data model” to
the visual studio project

6
1-Create Oracle Connection in VS

If you have already created an oracle connection , just double click on it


instead of clicking on connect to database
7
tiger

8
Scott connection will be added in
data connections

9
2- add entity data model item to
your form application

10
2- add entity data model item to
your form application (cont.)

11
2- add entity data model item to
your form application (cont.)

12
2- add entity data model item to
your form application (cont.)

13
2- add entity data model item to
your form application (cont.)

14
2- add entity data model item to
your form application (cont.)
2- add entity data model item to
your form application (cont.)

 Pluralize or singularize generated object names:


• Singularizes an entity name (class name), if the table name in
the database is plural. For example, if DB has FilmCopies table
name then entity (class) name would be singular FilmCopy.
• Also, the entityset (set of objects) of each entity (class) will be
pluralized. For example, the set of objects of (class which
named FilmCopy) named FilmCopies.
 Include foreign key columns in the model: includes foreign
key property explicitly to represent the foreign key.
 Import selected stored procedures and functions into
entity model: automatically creates Function Imports for the
stored procedures and functions. You don't need to manually
import this, as was necessary prior to Entity Framework 5.0.

16
Entity Data Model Designer
 EDM Designer represents the conceptual model.
 It consists of Entities, and associations & multiplicity between
the entities.
 If you choose many tables that have relations the entity model
will present the entities with their relations.

17
Entity-Table Mapping
 Each entity in EDM is mapped with the database table.

18
Entity-Table Mapping (cont.)

Columns of table Properties of entity

Mapping between columns


and properties
19
Entity data model Classes

 The system will generate a


DbContext class
named Entities.
 It contains entity set(s) for
each class generated in the
entity data model.
 An entity set is a collection
of objects of a specific
class and its name is the
same as the table name
(i.e. Filmcopies)

20
Entity Framework namespaces

21
Load Combobox With CopyIDs

22
Instantiating new object from db
context class “Entities”

 Create object of entities which is the


context class.

23
Queries in Entity Framework

 In Entity framework queries are written against the


classes and not against the database.
 Entity framework converts those queries to database
SQL Queries.
 Querying the data from entity framework could be done
using LINQ to Entities (Language Integrated Query).

24
Queries in Entity Framework (cont.)

Var Query is the Query Variable and it stores the query


rather than the results of the query.
From Clause must specify:
 The data source to be used (ent.FilmCopies)
ent.FilmCopies is an entity set for objects of type FilmCopy
 The range variable (fc)
 Temporarily holds a value from the data source.
 Can be compared to the iteration variable in a foreach loop.
 It’s data type is inferred by the compiler from the data source.
In this example data source is ent.FilmCopies. Hence the data
type of the range variable is an object from class (FilmCopy)
25
Executing query using ToList()

 Calling the ToList() method on query variable


forces the query to execute immediately and
return a list of objects of type FILMCOPy.

 FILMCOPy is the class generated based on table


filmcopies.

26
Filling the ComboBox with copy ids

 For each object (of type FilmCopy class)


in the copies list:
 Add to the combobox, the value in the
copyid property

27
29
Thank You

You might also like