Entity Framework, a quickstart Florin−Tudor Cristea, Microsoft Student Partner.

Slides:



Advertisements
Similar presentations
Satisfy Your Technical Curiosity ADO.NET vNext The Entity Data Model, Object Services, and LINQ Bob Beauchemin Director of Developer Resources, SQLskills.
Advertisements

.NET 3.5 SP1 New features Enhancements Visual Studio 2008 SP1 New features Enhancements Additional features/enhancements.
Michael Pizzo Software Architect Data Programmability Microsoft Corporation.
Technical BI Project Lifecycle
.NET Database Technologies: Open-Source Frameworks.
Building Enterprise Applications Using Visual Studio ®.NET Enterprise Architect.
Performed by:Gidi Getter Svetlana Klinovsky Supervised by:Viktor Kulikov 08/03/2009.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
A tour of new features introducing LINQ. Agenda of LINQ Presentation We have features for every step of the way LINQ Fundamentals Anonymous Functions/Lambda.
Discover, Master, InfluenceSlide 1 SQL Server Compact Edition and the Entity Framework Rob Sanders Readify.
SQL Server Compact Edition 3.5 and the Entity Framework Rob Sanders and Matt Lynch.
Introduction to ADO Entity Framework ir Denis VOITURON Source:
Eric Nelson Developer & Platform Group Microsoft Ltd
Some Basic Database Terminology
1 Entity Framework Introduction. Outline Goals of Entity Framework 2.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 1: Introduction.
Databases and LINQ Visual Basic 2010 How to Program 1.
LINQ Boot Camp ADO.Net Entity Framework Presenter : Date : Mahesh Moily Nov 26, 2009.
I Copyright © 2004, Oracle. All rights reserved. Introduction.
Web-Enabled Decision Support Systems
Visual Studio 2010 and.NET Framework 4 Training Workshop.
CST203-2 Database Management Systems Lecture 2. One Tier Architecture Eg: In this scenario, a workgroup database is stored in a shared location on a single.
Intro to C#.net and EF Ilan Shimshoni. The Three Faces of ADO.NET The connected layer – Directly connecting to the DB The disconnected layer – Using datasets.
Database System Concepts and Architecture
Introduction: Databases and Database Users
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
Entity Framework Overview. Entity Framework A set of technologies in ADO.NET that support the development of data-oriented software applications A component.
Open Data Protocol * Han Wang 11/30/2012 *
Ventsislav Popov Crossroad Ltd.. 1. ASP.NET Data Source Controls  SqlDataSource  EntityDataSource  ObjectDataSource 2. Entity Data Model and ADO.NET.
Chapter 1 : Introduction §Purpose of Database Systems §View of Data §Data Models §Data Definition Language §Data Manipulation Language §Transaction Management.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
Lap Around Visual Studio 2008 &.NET 3.5 Enhancements.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 14 Using Relational Databases to Provide Object Persistence (Overview) Modern Database.
Object Oriented Software Development 10. Persistent Storage.
Fanny Widadie, S.P, M.Agr 1 Database Management Systems.
Entity Framework Code First – Beyond the Basics Sergey Barskiy, Magenic Microsoft MVP – Data Platform Principal Consultant.
Oct * Brad Tutterow. VS 2008.NET 3.5LINQ Entity Framework  The ADO.NET Entity Framework is part of Microsoft’s next generation of.NET technologies.
EntityFrame work and LINQ CH 14. linq LINQ enables you to query data from a wide variety of data sources, directly from your programming code. LINQ is.
Course FAQ’s I do not have any knowledge on SQL concepts or Database Testing. Will this course helps me to get through all the concepts? What kind of.
Ventsislav Popov Crossroad Ltd.. 1. ASP.NET Data Source Controls  SqlDataSource  EntityDataSource  ObjectDataSource 2. Entity Data Model and ADO.NET.
BI Practice March-2006 COGNOS 8BI TOOLS COGNOS 8 Framework Manager TATA CONSULTANCY SERVICES SEEPZ, Mumbai.
Mr.Prasad Sawant, MIT Pune India Introduction to DBMS.
NSF DUE ; Wen M. Andrews J. Sargeant Reynolds Community College Richmond, Virginia.
Entity Framework Code First – Beyond the Basics Sergey Barskiy, Magenic Microsoft MVP – Data Platform Magenic, Principal Consultant Level: Introductory.
1 Chapter 2 Database Environment Pearson Education © 2009.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
ASET 1 Amity School of Engineering & Technology B. Tech. (CSE/IT), III Semester Database Management Systems Jitendra Rajpurohit.
ADO.NET 3.0 – Entity Data Model Gert E.R. Drapers Chief Software Architect Visual Studio Team Edition for Database Professionals Microsoft Corporation.
Presentation on Database management Submitted To: Prof: Rutvi Sarang Submitted By: Dharmishtha A. Baria Roll:No:1(sem-3)
2 Behind every great site, there is great data Eric Nelson Developer Evangelist Microsoft UK
Entity Framework Database Connection with ASP Notes from started/getting-started-with-ef-using-mvc/creating-an-
Submitted by: Moran Mishan. Instructed by: Osnat (Ossi) Mokryn, Dr.
1 Management Information Systems M Agung Ali Fikri, SE. MM.
1 Copyright © 2008, Oracle. All rights reserved. Repository Basics.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
© 2016, Mike Murach & Associates, Inc.
Introduction to Entity Framework
Chris Menegay Sr. Consultant TECHSYS Business Solutions
Entity Framework By: Casey Griffin.
Chapter 4 Relational Databases
Entity Framework 4 and WCF Data Services 4
ADO.NET Entity Framework Marcus Tillett
ADO.NET Entity Framework
.NET Database Technologies:
Data Model.
Database Systems Instructor Name: Lecture-3.
ADO.NET Entity Framework
Visual Studio 2010 and .NET Framework 4 Training Workshop
Presentation transcript:

Entity Framework, a quickstart Florin−Tudor Cristea, Microsoft Student Partner

The ADO.NET Entity Framework (EF) supports data-centric applications and services, and provides a platform for programming against data that raises the level of abstraction from the logical relational level to the conceptual level. By enabling developers to work with data at a greater level of abstraction, the EF supports code that is independent of any particular data storage engine or relational schema.

The Entity Data Model (EDM) is a set of concepts that describe the structure of data, regardless of its stored form. In some ways, it is similar to a database view in that it can consolidate information from multiple sources. But it goes beyond a view in several ways. First, unlike a view, the conceptual EDM includes information about the source of the data so that the tools have enough information about the creation.

This metadata indicates where the values came from and consequently where they will go when updated. Additionally, the EDM includes the ability to store both objects and relationships necessary to create fully dynamic object hierarchies in a conceptual model. The EF separates the physical from the logical models by using a series of XML- based mapping files.

In the EF, the physical database is mapped to a logical model using a one-to-one relationship between the tables and logical layer entities. The logical entities are defined through an XML-based Store Schema Definition Language (SSDL) file. These mappings are similar to those definable in LINQ to SQL.

The EF moves beyond LINQ to SQL by using another XML-based file (Mapping Schema Language or MSL) to map the logical model to a conceptual model. The conceptual model is yet another XML file using a Conceptual Schema Definition Language (CSDL). These conceptual entities can be further converted into strongly typed objects if desired.

With the EDM established, we can query it with a string-based query language called Entity SQL. In addition, our LINQ knowledge can be applied against the EDM by using LINQ to Entities. The separation of layers we get from the EDM allows for an increased separation between the physical and logical. This allows us to change our data model and mapping structures and leave our application intact.

Physical Logical SSDL Mapping MSL Conceptual CSDL Author User Address Publisher Author Entity Publisher Entity AuthorClass PublisherClass Layers of the Entity Framework

The EF supports the EDM for defining data at the conceptual level. When using the ADO.NET Entity Data Model Designer, conceptual model, storage model, and mapping information is contained in an.edmx file. The EF also enables developers to program directly against the data types defined at the conceptual level as common language runtime (CLR) objects.

The EF provides tools to generate an.edmx file and the related CLR objects based on an existing database. This reduces much of the data access code that used to be required to create object-based data application and services, and makes it faster to create object-oriented data applications and services from an existing database.

The tools also allow you to build a conceptual model first, then automatically generate related CLR objects and a supporting database.

us/library/bb aspx Task 1: creating the School sample database Create the School database schema and load data into the database. SQL Server Express Utility Scripts/CreateSchool.sql

Task 2: creating the course manager application Create a Windows Forms application to access data in the School model. closeForm_Click: this.Close()

Task 3: generating the School entity data model Use Visual Studio tools to generate model and mapping information based on the School database.

Task 4: querying entities and associations Create queries against the entities and associations in the School model, and bind controls to the results of those queries. using System.Data.Objects; using System.Data.Objects.DataClasses; private SchoolEntities schoolContext;

courseViewer_Load: // Initialize the ObjectContext. schoolContext = new SchoolEntities(); // Define a query that returns all Department // objects and course objects, ordered by name. var departmentQuery = from d in schoolContext.Departments.Include("Courses") orderby d.Name select d; try { // Bind the ComboBox control to the query, // which is executed during data binding. // To prevent the query from being executed multiple times during binding, // it is recommended to bind controls to the result of the Execute method. this.departmentList.DisplayMember = "Name"; this.departmentList.DataSource = ((ObjectQuery)departmentQuery).Execute(MergeOption.AppendOnly); } catch (Exception ex) { MessageBox.Show(ex.Message); }

departmentList_SelectedIndexChanged: try { // Get the object for the selected department. Department department = (Department)this.departmentList.SelectedItem; // Bind the grid view to the collection of Course objects // that are related to the selected Department object. courseGridView.DataSource = department.Courses; // Hide the columns that are bound to the navigation properties on Course. courseGridView.Columns["Department"].Visible = false; courseGridView.Columns["StudentGrades"].Visible = false; courseGridView.Columns["OnlineCourse"].Visible = false; courseGridView.Columns["OnsiteCourse"].Visible = false; courseGridView.Columns["People"].Visible = false; courseGridView.Columns["DepartmentId"].Visible = false; courseGridView.AllowUserToDeleteRows = false; courseGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); } catch (Exception ex) { MessageBox.Show(ex.Message); }

Task 5: inserting and updating data Save changes to object data made by using data controls to the School database. closeForm_Click: // Dispose the object context. schoolContext.Dispose();

saveChanges_Click: try { // Save object changes to the database, // display a message, and refresh the form. schoolContext.SaveChanges(); MessageBox.Show("Changes saved to the database."); this.Refresh(); } catch(Exception ex) { MessageBox.Show(ex.Message); }

Lazy loading // First, using LINQ to SQL: L2SDataContext dc = new L2SDataContext(); this.DataGrid1.DataSource = dc.Customers.First().Orders; // => 3 records in the data grid this.DataGrid1.DataBind();

// Using the Entity Framework: EFEntities efc = new EFEntities(); this.DataGrid2.DataSource = efc.Customers.First().Orders; // => 0 records in the data grid! this.DataGrid2.DataBind();

LINQ to SQL automatically went back to the database and loaded the orders for that first customer. The team behind EF didn't want this automatic behavior happening: when architecting a larger project, it is highly important for developers to clearly understand when they are accessing certain resources, such as the database.

// Explicitly include the orders from the database in one shot: this.DataGrid2.DataSource = efc.Customers.Include("Orders").First ().Orders; // OR // Explicitly load the orders after retrieving the customer: var customer = efc.Customers.First(); customer.Orders.Load(); this.DataGrid2.DataSource = customer.Orders;

m/EFLazyLoading

m/EFDocSamples2008 (HRSkillsCombined.zip)

Good luck, and keep in touch!