A Comparative Look at Entity Framework Code First Casey Griffin La Salle University, [email protected]
Total Page:16
File Type:pdf, Size:1020Kb
La Salle University La Salle University Digital Commons Mathematics and Computer Science, Department Mathematics and Computer Science Capstones of Spring 5-17-2013 A Comparative Look at Entity Framework Code First Casey Griffin La Salle University, [email protected] Follow this and additional works at: http://digitalcommons.lasalle.edu/mathcompcapstones Part of the Databases and Information Systems Commons Recommended Citation Griffin,as C ey, "A Comparative Look at Entity Framework Code First" (2013). Mathematics and Computer Science Capstones. 11. http://digitalcommons.lasalle.edu/mathcompcapstones/11 This Thesis is brought to you for free and open access by the Mathematics and Computer Science, Department of at La Salle University Digital Commons. It has been accepted for inclusion in Mathematics and Computer Science Capstones by an authorized administrator of La Salle University Digital Commons. For more information, please contact [email protected]. A Comparative Look at Entity Framework Code First Submitted to the Department of Computer Information Science By: Casey Griffin Date: May 1, 2013 La Salle University MS Computer Information Science/MS Information Technology Leadership APPROVALS Agree to Advise: Stephen A. Longo, Ph.D. (Project Advisor) Date Submitted: May 1st, 2013 Approved by: Stephen A. Longo, Ph.D. (MS in CS Committee) Date Approved: May 3rd, 2013 1 La Salle University MS Computer Information Science/MS Information Technology Leadership Contents 1. Abstract ....................................................................................................................... 6 2. Introduction ................................................................................................................. 7 3. Background ............................................................................................................... 10 3.1 Microsoft .NET Framework and ADO.NET ...................................................... 10 3.2 Entity Framework ............................................................................................... 11 3.3 Conceptual Model .............................................................................................. 13 3.4 Development Workflows ................................................................................... 13 3.5 Code First Approach .......................................................................................... 15 3.5.1 Plan Old CLR Objects (POCO) Classes ..................................................... 15 3.5.2 DbContext API............................................................................................ 16 3.5.3 Code First Conventions............................................................................... 16 3.5.4 Data Annotations and the Fluent API ......................................................... 17 3.5.5 Code First Migrations ................................................................................. 18 4. Methodologies........................................................................................................... 20 4.1 Example: Griffin Drywall .................................................................................. 20 4.2 Business Requirements ...................................................................................... 21 4.3 EF Code First ..................................................................................................... 23 4.3.1 POCO Classes ............................................................................................. 23 4.3.2 DbContext API............................................................................................ 26 4.3.3 Code First Migrations ................................................................................. 26 4.4 The Website........................................................................................................ 27 4.4.1 Master Page ................................................................................................. 27 4.4.2 Home Page .................................................................................................. 28 4.4.3 Request Bid Pages....................................................................................... 29 4.4.4 Services Page .............................................................................................. 30 4.4.5 Project Pages ............................................................................................... 31 4.4.6 Contact Us Page .......................................................................................... 33 4.4.7 Account Management ................................................................................. 34 4.4.8 Admin Services ........................................................................................... 35 4.4.9 Subcontractor Page ..................................................................................... 35 5. Analysis..................................................................................................................... 37 5.1 Entity Framework Features ................................................................................ 37 2 La Salle University MS Computer Information Science/MS Information Technology Leadership 5.1.1 LINQ ........................................................................................................... 38 5.2 Code First Implementation ................................................................................. 41 5.2.1 POCO Classes ............................................................................................. 41 5.2.2 DbContext API............................................................................................ 45 5.2.3 Code First Migrations ................................................................................. 47 5.3 Traditional Approach Comparison ..................................................................... 49 5.3.1 Criticism ...................................................................................................... 50 5.3.2 Entity Framework Advantages ................................................................... 51 5.4 Griffin Drywall Development ............................................................................ 53 6. Conclusion ................................................................................................................ 59 6.1 Further Research ................................................................................................ 60 7. Appendix A ............................................................................................................... 62 7.1 Company ............................................................................................................ 62 7.2 GImage ............................................................................................................... 62 7.3 Job ...................................................................................................................... 63 7.4 Project................................................................................................................. 63 7.5 Request ............................................................................................................... 64 7.6 Service ................................................................................................................ 65 7.7 ServiceType ........................................................................................................ 66 7.8 Subcontractor ..................................................................................................... 66 7.9 Work ................................................................................................................... 67 7.10 WorkDetails .................................................................................................... 67 8. Appendix B ............................................................................................................... 69 8.1 GriffinContext DbContext.................................................................................. 69 9. Appendix C ............................................................................................................... 71 9.1 Initial Migration (First) ...................................................................................... 71 9.2 Add-ServiceType ............................................................................................... 72 9.3 Add-Request ....................................................................................................... 72 9.4 Add-Job .............................................................................................................. 74 9.5 Add-Subcon ........................................................................................................ 74 9.6 Add-Work........................................................................................................... 75 9.7 SubCon-Change ................................................................................................. 76 9.8 SubCon-Change2 ............................................................................................... 77 9.9 SubCon-Change3 ............................................................................................... 77 3 La Salle University MS Computer Information Science/MS Information Technology Leadership 9.10 SubCon-Change4 ...........................................................................................