LINQ and the Entity Framework

Download Report

Transcript LINQ and the Entity Framework

Entity Framework
MIS 324
Professor Sandvig
Outline
 What
is Entity Framework
 Benefits
 Drawbacks
 Example
What is Entity Framework
 Microsoft’s
newest data access technology
 Visual Studio:


Examines database
Creates objects that represent data schema
 LINQ


(Language Integrated Query)
Replaces SQL
Select, sort, filter, etc.
Benefits
 Eliminates
disconnect between code &
database

No sql statements in code
 Use
intellisense to write query
 Automatic table joins
 Full CRUD functionality
 LINQ works on all data collections

Arrays, lists, dataviews, etc.
Drawbacks
 Microsoft
propriety technology
 LINQ query syntax different than SQL

Better in many ways
 Synchronization
between database and
entity objects


Change database
Rebuild entity objects
Example

Visual Studio:
1. Create new Dynamic Data Entities Web Site
2.
Add new item:
ADO Data
Entity Model
Example
3.
4.
Select “Generate from Database”
Select Sql Server database


5.
Express or full version
Note: table relationships MUST be defined in
Database Diagram
Wizard creates new Namespace

Contains data objects that match database
Entity Model Designer Window
 Note:
many-to-many relationship
LINQ
 Use
LINQ to query against data objects
LINQ Syntax
 Var
datatype uses implicit typing
 Similar to DataTable
Example
 Retail
Store Example