USANDO EL ENTITY
    FRAMEWORK

  Juan Camilo Sacanamboy
ENTITY FRAMEWORK




Fuente: MSDN (Working with Data in ASP.NET MVC 3)
ENTITY FRAMEWORK




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
CONTOSO UNIVERSITY




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
CONTOSO UNIVERSITY




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
CONTOSO UNIVERSITY




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
POCO

   • Plain Old CLR Objects
   • POCO Class  Persistence ignorance
   • Design – Build – Test
       – Independently of
            • Database
            • Persistence infrastructure code
   • Focus on the business problem


Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
DATA MODEL




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
STUDENT ENTITY




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
ENROLLMENT ENTITY




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
COURSE ENTITY




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
DATABASE CONTEXT




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
CONNECTION STRING

   • SQL Server Compact
            <add name="SchoolContext" connectionString="Data
            Source=|DataDirectory|School.sdf"
            providerName="System.Data.SqlServerCe.4.0"/>




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
Initializing the Database with test data

   •   using   System;
       using   System.Collections.Generic;
       using   System.Linq;
       using   System.Web;
       using   System.Data.Entity;
       using   ContosoUniversity.Models;

       namespace ContosoUniversity.DAL
       {
           public class SchoolInitializer : DropCreateDatabaseIfModelChanges<SchoolContext>
           {
               protected override void Seed(SchoolContext context)
               {
                   var students = new List<Student>
                   {
                       new Student { FirstMidName = "Carson",   LastName = "Alexander", EnrollmentDate   =
       DateTime.Parse("2005-09-01") },
                       new Student { FirstMidName = "Meredith", LastName = "Alonso",    EnrollmentDate   =
       DateTime.Parse("2002-09-01") },
                       new Student { FirstMidName = "Arturo",   LastName = "Anand",     EnrollmentDate   =
       DateTime.Parse("2003-09-01") },
                       new Student { FirstMidName = "Gytis",    LastName = "Barzdukas", EnrollmentDate   =
       DateTime.Parse("2002-09-01") },
                       new Student { FirstMidName = "Yan",      LastName = "Li",        EnrollmentDate   =
       DateTime.Parse("2002-09-01") },
                       new Student { FirstMidName = "Peggy",    LastName = "Justice",   EnrollmentDate   =
       DateTime.Parse("2001-09-01") },
                       new Student { FirstMidName = "Laura",    LastName = "Norman",    EnrollmentDate   =
       DateTime.Parse("2003-09-01") },
                       new Student { FirstMidName = "Nino",     LastName = "Olivetto", EnrollmentDate    =
       DateTime.Parse("2005-09-01") }
                   };
                   students.ForEach(s => context.Students.Add(s));
                   context.SaveChanges();

Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
Initializing the Database with test data

   •   var courses = new List<Course>
                  {
                      new Course { Title = "Chemistry",      Credits   =   3,   },
                      new Course { Title = "Microeconomics", Credits   =   3,   },
                      new Course { Title = "Macroeconomics", Credits   =   3,   },
                      new Course { Title = "Calculus",       Credits   =   4,   },
                      new Course { Title = "Trigonometry",   Credits   =   4,   },
                      new Course { Title = "Composition",    Credits   =   3,   },
                      new Course { Title = "Literature",     Credits   =   4,   }
                  };
                  courses.ForEach(s => context.Courses.Add(s));
                  context.SaveChanges();

                   var enrollments = new List<Enrollment>
                   {
                       new Enrollment { StudentID = 1, CourseID = 1, Grade      =   1
                                                                                    },
                       new Enrollment { StudentID = 1, CourseID = 2, Grade      =   3
                                                                                    },
                       new Enrollment { StudentID = 1, CourseID = 3, Grade      =   1
                                                                                    },
                       new Enrollment { StudentID = 2, CourseID = 4, Grade      =   2
                                                                                    },
                       new Enrollment { StudentID = 2, CourseID = 5, Grade      =   4
                                                                                    },
                       new Enrollment { StudentID = 2, CourseID = 6, Grade      =   4
                                                                                    },
                       new Enrollment { StudentID = 3, CourseID = 1                 },
                       new Enrollment { StudentID = 4, CourseID = 1,                },
                       new Enrollment { StudentID = 4, CourseID = 2, Grade      = 4 },
                       new Enrollment { StudentID = 5, CourseID = 3, Grade      = 3 },
                       new Enrollment { StudentID = 6, CourseID = 4                 },
                       new Enrollment { StudentID = 7, CourseID = 5, Grade      = 2 },
                   };
                   enrollments.ForEach(s => context.Enrollments.Add(s));
                   context.SaveChanges();
               }
           }
       }

Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
Global.asax.cs




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
Creating a Student Controller




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
StudentController.cs




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
ViewsStudentIndex.cshtml

   •   @model IEnumerable<ContosoUniversity.Models.Student>

       @{
             ViewBag.Title = "Students";
       }

       <h2>Students</h2>

       <p>
           @Html.ActionLink("Create New", "Create")
       </p>
       <table>
           <tr>
               <th></th>
               <th>Last Name</th>
               <th>First Name</th>
               <th>Enrollment Date</th>
           </tr>


Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
ViewsStudentIndex.cshtml

   •   @foreach (var item in Model) {
           <tr>
                <td>
                     @Html.ActionLink("Edit", "Edit", new { id=item.StudentID }) |
                     @Html.ActionLink("Details", "Details", new { id=item.StudentID })
       |
                     @Html.ActionLink("Delete", "Delete", new { id=item.StudentID })
                </td>
                <td>
                     @Html.DisplayFor(modelItem => item.LastName)
                </td>
                <td>
                     @Html.DisplayFor(modelItem => item.FirstMidName)
                </td>
                <td>
                     @Html.DisplayFor(modelItem => item.EnrollmentDate)
                </td>
           </tr>
       }

       </table>


Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
Running application




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
Solution Explorer




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
Solution Explorer




Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
Conventions

• Los nombres de las entidades en plural son los
  nombres de las tablas.
• Los nombres de las propiedades de las
  entidades son las columnas de las tablas.
• Las propiedades llamadas ID o *ID son
  reconocidas como claves primarias.
• El EF se conecta a la base de datos buscando
  un string de conexión que tenga el mismo
  nombre de la clase contexto. (SchoolContext)
Usando el entity framework

More Related Content

PDF
The Ring programming language version 1.5.3 book - Part 83 of 184
PPTX
Java Course Day 3
PDF
Java OOP Programming language (Part 4) - Collection
PDF
PDF
The Ring programming language version 1.8 book - Part 80 of 202
PPS
CS101- Introduction to Computing- Lecture 26
PPT
POLITEKNIK MALAYSIA
PDF
Java OOP Programming language (Part 8) - Java Database JDBC
The Ring programming language version 1.5.3 book - Part 83 of 184
Java Course Day 3
Java OOP Programming language (Part 4) - Collection
The Ring programming language version 1.8 book - Part 80 of 202
CS101- Introduction to Computing- Lecture 26
POLITEKNIK MALAYSIA
Java OOP Programming language (Part 8) - Java Database JDBC

What's hot (10)

PPT
PDF
Java OOP Programming language (Part 3) - Class and Object
PDF
The Ring programming language version 1.5.4 book - Part 73 of 185
PPTX
R environment
PDF
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
PPTX
11. session 11 functions and objects
PDF
The Ring programming language version 1.5.2 book - Part 70 of 181
PPT
PPTX
Ggplot2 v3
PDF
Scala Domain Modeling and Architecture
Java OOP Programming language (Part 3) - Class and Object
The Ring programming language version 1.5.4 book - Part 73 of 185
R environment
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
11. session 11 functions and objects
The Ring programming language version 1.5.2 book - Part 70 of 181
Ggplot2 v3
Scala Domain Modeling and Architecture
Ad

Viewers also liked (6)

PDF
UX for developers
PDF
Keep calm and write reusable code in Android
PDF
Problema del barbero durmiente
PDF
Modelado de circuitos con ED de orden superior
UX for developers
Keep calm and write reusable code in Android
Problema del barbero durmiente
Modelado de circuitos con ED de orden superior
Ad

Similar to Usando el entity framework (20)

PPTX
DDD Modeling Workshop
PPTX
MVC and Entity Framework
PDF
Mvc4 crud operations.-kemuning senja
PDF
Entity frame work by Salman Mushtaq -1-
DOCX
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
PDF
Getting started with the entity framework 4.1 using asp.net mvc
PPT
Introduction to Linq
PPTX
Linq Introduction
DOCX
Learning MVC Part 3 Creating MVC Application with EntityFramework
PPTX
MVC and Entity Framework 4
PDF
Getting started with entity framework 6 code first using mvc 5
PDF
An Overview of Entity Framework
PDF
Nhibernate Part 1
PPTX
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
PPTX
Entity Framework: Code First and Magic Unicorns
DOCX
Create methods to_insert
DOCX
MVC Application using EntityFramework Code-First approach Part4
PPT
ASP.NET 08 - Data Binding And Representation
PPTX
Overview of entity framework by software outsourcing company india
DDD Modeling Workshop
MVC and Entity Framework
Mvc4 crud operations.-kemuning senja
Entity frame work by Salman Mushtaq -1-
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Getting started with the entity framework 4.1 using asp.net mvc
Introduction to Linq
Linq Introduction
Learning MVC Part 3 Creating MVC Application with EntityFramework
MVC and Entity Framework 4
Getting started with entity framework 6 code first using mvc 5
An Overview of Entity Framework
Nhibernate Part 1
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
Entity Framework: Code First and Magic Unicorns
Create methods to_insert
MVC Application using EntityFramework Code-First approach Part4
ASP.NET 08 - Data Binding And Representation
Overview of entity framework by software outsourcing company india

More from Juan Camilo Sacanamboy (8)

PDF
OFDM (Orthogonal Frequency Division Multiplexing )
PDF
Functional Testing
PDF
FTP (File Transfer Protocol)
PDF
Protocolo de Enrutamiento RIP (Versiones 1 y 2)
PDF
PDF
Ecuación de bessel
PDF
Algoritmo JPEG
PDF
Tutorial ASP .NET
OFDM (Orthogonal Frequency Division Multiplexing )
Functional Testing
FTP (File Transfer Protocol)
Protocolo de Enrutamiento RIP (Versiones 1 y 2)
Ecuación de bessel
Algoritmo JPEG
Tutorial ASP .NET

Recently uploaded (20)

PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PPTX
agenticai-neweraofintelligence-250529192801-1b5e6870.pptx
PDF
SaaS reusability assessment using machine learning techniques
PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
PDF
A symptom-driven medical diagnosis support model based on machine learning te...
PDF
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
PDF
INTERSPEECH 2025 「Recent Advances and Future Directions in Voice Conversion」
PPTX
Build automations faster and more reliably with UiPath ScreenPlay
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
Advancing precision in air quality forecasting through machine learning integ...
PDF
Auditboard EB SOX Playbook 2023 edition.
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
Human Computer Interaction Miterm Lesson
PDF
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
PDF
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
PDF
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
PDF
Rapid Prototyping: A lecture on prototyping techniques for interface design
PPTX
Module 1 Introduction to Web Programming .pptx
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
agenticai-neweraofintelligence-250529192801-1b5e6870.pptx
SaaS reusability assessment using machine learning techniques
NewMind AI Weekly Chronicles – August ’25 Week IV
A symptom-driven medical diagnosis support model based on machine learning te...
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
INTERSPEECH 2025 「Recent Advances and Future Directions in Voice Conversion」
Build automations faster and more reliably with UiPath ScreenPlay
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
Advancing precision in air quality forecasting through machine learning integ...
Auditboard EB SOX Playbook 2023 edition.
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
Human Computer Interaction Miterm Lesson
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
Rapid Prototyping: A lecture on prototyping techniques for interface design
Module 1 Introduction to Web Programming .pptx
AI.gov: A Trojan Horse in the Age of Artificial Intelligence

Usando el entity framework

  • 1. USANDO EL ENTITY FRAMEWORK Juan Camilo Sacanamboy
  • 2. ENTITY FRAMEWORK Fuente: MSDN (Working with Data in ASP.NET MVC 3)
  • 3. ENTITY FRAMEWORK Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 4. CONTOSO UNIVERSITY Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 5. CONTOSO UNIVERSITY Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 6. CONTOSO UNIVERSITY Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 7. POCO • Plain Old CLR Objects • POCO Class  Persistence ignorance • Design – Build – Test – Independently of • Database • Persistence infrastructure code • Focus on the business problem Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 8. DATA MODEL Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 9. STUDENT ENTITY Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 10. ENROLLMENT ENTITY Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 11. COURSE ENTITY Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 12. DATABASE CONTEXT Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 13. CONNECTION STRING • SQL Server Compact <add name="SchoolContext" connectionString="Data Source=|DataDirectory|School.sdf" providerName="System.Data.SqlServerCe.4.0"/> Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 14. Initializing the Database with test data • using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity; using ContosoUniversity.Models; namespace ContosoUniversity.DAL { public class SchoolInitializer : DropCreateDatabaseIfModelChanges<SchoolContext> { protected override void Seed(SchoolContext context) { var students = new List<Student> { new Student { FirstMidName = "Carson", LastName = "Alexander", EnrollmentDate = DateTime.Parse("2005-09-01") }, new Student { FirstMidName = "Meredith", LastName = "Alonso", EnrollmentDate = DateTime.Parse("2002-09-01") }, new Student { FirstMidName = "Arturo", LastName = "Anand", EnrollmentDate = DateTime.Parse("2003-09-01") }, new Student { FirstMidName = "Gytis", LastName = "Barzdukas", EnrollmentDate = DateTime.Parse("2002-09-01") }, new Student { FirstMidName = "Yan", LastName = "Li", EnrollmentDate = DateTime.Parse("2002-09-01") }, new Student { FirstMidName = "Peggy", LastName = "Justice", EnrollmentDate = DateTime.Parse("2001-09-01") }, new Student { FirstMidName = "Laura", LastName = "Norman", EnrollmentDate = DateTime.Parse("2003-09-01") }, new Student { FirstMidName = "Nino", LastName = "Olivetto", EnrollmentDate = DateTime.Parse("2005-09-01") } }; students.ForEach(s => context.Students.Add(s)); context.SaveChanges(); Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 15. Initializing the Database with test data • var courses = new List<Course> { new Course { Title = "Chemistry", Credits = 3, }, new Course { Title = "Microeconomics", Credits = 3, }, new Course { Title = "Macroeconomics", Credits = 3, }, new Course { Title = "Calculus", Credits = 4, }, new Course { Title = "Trigonometry", Credits = 4, }, new Course { Title = "Composition", Credits = 3, }, new Course { Title = "Literature", Credits = 4, } }; courses.ForEach(s => context.Courses.Add(s)); context.SaveChanges(); var enrollments = new List<Enrollment> { new Enrollment { StudentID = 1, CourseID = 1, Grade = 1 }, new Enrollment { StudentID = 1, CourseID = 2, Grade = 3 }, new Enrollment { StudentID = 1, CourseID = 3, Grade = 1 }, new Enrollment { StudentID = 2, CourseID = 4, Grade = 2 }, new Enrollment { StudentID = 2, CourseID = 5, Grade = 4 }, new Enrollment { StudentID = 2, CourseID = 6, Grade = 4 }, new Enrollment { StudentID = 3, CourseID = 1 }, new Enrollment { StudentID = 4, CourseID = 1, }, new Enrollment { StudentID = 4, CourseID = 2, Grade = 4 }, new Enrollment { StudentID = 5, CourseID = 3, Grade = 3 }, new Enrollment { StudentID = 6, CourseID = 4 }, new Enrollment { StudentID = 7, CourseID = 5, Grade = 2 }, }; enrollments.ForEach(s => context.Enrollments.Add(s)); context.SaveChanges(); } } } Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 16. Global.asax.cs Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 17. Creating a Student Controller Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 18. StudentController.cs Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 19. ViewsStudentIndex.cshtml • @model IEnumerable<ContosoUniversity.Models.Student> @{ ViewBag.Title = "Students"; } <h2>Students</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table> <tr> <th></th> <th>Last Name</th> <th>First Name</th> <th>Enrollment Date</th> </tr> Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 20. ViewsStudentIndex.cshtml • @foreach (var item in Model) { <tr> <td> @Html.ActionLink("Edit", "Edit", new { id=item.StudentID }) | @Html.ActionLink("Details", "Details", new { id=item.StudentID }) | @Html.ActionLink("Delete", "Delete", new { id=item.StudentID }) </td> <td> @Html.DisplayFor(modelItem => item.LastName) </td> <td> @Html.DisplayFor(modelItem => item.FirstMidName) </td> <td> @Html.DisplayFor(modelItem => item.EnrollmentDate) </td> </tr> } </table> Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 21. Running application Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 22. Solution Explorer Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 23. Solution Explorer Fuente: MSDN (Creating an Entity Framework Data Model for an ASP.NET MVC Application)
  • 24. Conventions • Los nombres de las entidades en plural son los nombres de las tablas. • Los nombres de las propiedades de las entidades son las columnas de las tablas. • Las propiedades llamadas ID o *ID son reconocidas como claves primarias. • El EF se conecta a la base de datos buscando un string de conexión que tenga el mismo nombre de la clase contexto. (SchoolContext)