SlideShare a Scribd company logo
1 of 25
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

What's hot

Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectOUM SAOKOSAL
 
The Ring programming language version 1.5.4 book - Part 73 of 185
The Ring programming language version 1.5.4 book - Part 73 of 185The Ring programming language version 1.5.4 book - Part 73 of 185
The Ring programming language version 1.5.4 book - Part 73 of 185Mahmoud Samir Fayed
 
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...scalaconfjp
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objectsPhúc Đỗ
 
The Ring programming language version 1.5.2 book - Part 70 of 181
The Ring programming language version 1.5.2 book - Part 70 of 181The Ring programming language version 1.5.2 book - Part 70 of 181
The Ring programming language version 1.5.2 book - Part 70 of 181Mahmoud Samir Fayed
 
Scala Domain Modeling and Architecture
Scala Domain Modeling and ArchitectureScala Domain Modeling and Architecture
Scala Domain Modeling and ArchitectureHossam Karim
 

What's hot (10)

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

Viewers also liked (6)

NRZ code
NRZ codeNRZ code
NRZ code
 
UX for developers
UX for developersUX for developers
UX for developers
 
Keep calm and write reusable code in Android
Keep calm and write reusable code in AndroidKeep calm and write reusable code in Android
Keep calm and write reusable code in Android
 
Problema del barbero durmiente
Problema del barbero durmienteProblema del barbero durmiente
Problema del barbero durmiente
 
Modelado de circuitos con ED de orden superior
Modelado de circuitos con ED de orden superiorModelado de circuitos con ED de orden superior
Modelado de circuitos con ED de orden superior
 
FDDI
FDDIFDDI
FDDI
 

Similar to Usando el entity framework

APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...DEEPANSHU GUPTA
 
Hello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and ClassesHello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and ClassesCody Yun
 
Java Foundations: Objects and Classes
Java Foundations: Objects and ClassesJava Foundations: Objects and Classes
Java Foundations: Objects and ClassesSvetlin Nakov
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring DataOliver Gierke
 
Paintfree Object-Document Mapping for MongoDB by Philipp Krenn
Paintfree Object-Document Mapping for MongoDB by Philipp KrennPaintfree Object-Document Mapping for MongoDB by Philipp Krenn
Paintfree Object-Document Mapping for MongoDB by Philipp KrennJavaDayUA
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Oliver Gierke
 
Modul Praktek Java OOP
Modul Praktek Java OOP Modul Praktek Java OOP
Modul Praktek Java OOP Zaenal Arifin
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfforwardcom41
 
How to implement g rpc services in nodejs
How to implement g rpc services in nodejsHow to implement g rpc services in nodejs
How to implement g rpc services in nodejsKaty Slemon
 
11. Java Objects and classes
11. Java  Objects and classes11. Java  Objects and classes
11. Java Objects and classesIntro C# Book
 
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenTutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenSony Suci
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++Arpita Patel
 
[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancjiJakub Marchwicki
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slotsmha4
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slotsmha4
 

Similar to Usando el entity framework (20)

662305 09
662305 09662305 09
662305 09
 
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
 
Hello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and ClassesHello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and Classes
 
Java Foundations: Objects and Classes
Java Foundations: Objects and ClassesJava Foundations: Objects and Classes
Java Foundations: Objects and Classes
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
 
Paintfree Object-Document Mapping for MongoDB by Philipp Krenn
Paintfree Object-Document Mapping for MongoDB by Philipp KrennPaintfree Object-Document Mapping for MongoDB by Philipp Krenn
Paintfree Object-Document Mapping for MongoDB by Philipp Krenn
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
Modul Praktek Java OOP
Modul Praktek Java OOP Modul Praktek Java OOP
Modul Praktek Java OOP
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdf
 
How to implement g rpc services in nodejs
How to implement g rpc services in nodejsHow to implement g rpc services in nodejs
How to implement g rpc services in nodejs
 
Spring data
Spring dataSpring data
Spring data
 
11. Java Objects and classes
11. Java  Objects and classes11. Java  Objects and classes
11. Java Objects and classes
 
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenTutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
 
Spsl vi unit final
Spsl vi unit finalSpsl vi unit final
Spsl vi unit final
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
 
[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
Green dao 3.0
Green dao 3.0Green dao 3.0
Green dao 3.0
 

More from Juan Camilo Sacanamboy (8)

OFDM (Orthogonal Frequency Division Multiplexing )
OFDM (Orthogonal Frequency Division Multiplexing �)OFDM (Orthogonal Frequency Division Multiplexing �)
OFDM (Orthogonal Frequency Division Multiplexing )
 
Functional Testing
Functional TestingFunctional Testing
Functional Testing
 
FTP (File Transfer Protocol)
FTP (File Transfer Protocol)FTP (File Transfer Protocol)
FTP (File Transfer Protocol)
 
Protocolo de Enrutamiento RIP (Versiones 1 y 2)
Protocolo de Enrutamiento RIP (Versiones 1 y 2)Protocolo de Enrutamiento RIP (Versiones 1 y 2)
Protocolo de Enrutamiento RIP (Versiones 1 y 2)
 
Infrarrojo
InfrarrojoInfrarrojo
Infrarrojo
 
Ecuación de bessel
Ecuación de besselEcuación de bessel
Ecuación de bessel
 
Algoritmo JPEG
Algoritmo JPEGAlgoritmo JPEG
Algoritmo JPEG
 
Tutorial ASP .NET
Tutorial ASP .NETTutorial ASP .NET
Tutorial ASP .NET
 

Recently uploaded

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

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)