OLD Entity Framework & Database First Coding

  1. What is Entity Framework? Describe its main components.
    Entity Framework (EF) is an open source object-relational mapping (ORM) framework for ADO.NET originally designed for the .NET framework but has since evolved into its own framework. It typically consists of two libraries which work together to model the database using class (domain classes) from a table to a persisted in-memory DbSet object which often allows for CRUD capabilities using one of three design techniques: code first, database first, or model first.
  2. What file names & content is created when first generating a DB-first data model called EducationModel? Name each of the main files and their subfolders and also what their contents represent.
    • EducationModel.edmx: contains the data designer model of each table
    • EducationModel.Context.tt: template file, never gets modified
    • EducationConnection: string connecting to the database, found in project app.config
    • EducationContext: implements base class of DbContext library which possesses all the heavy lifting libraries used for connectivity & database modifications [located outside of this application]
    • EducationModel.tt: template file, not sed
    • Classes: Contain basic public classes (aka domain classes) such as Teacher.cs, Student.cs and Schedule.cs
  3. Where would I go to do the following?
       a. Change the name of the connection string?
       b. Make a change to a table class?
       c. Generate new method for a class?
       d. Update a stored procedure or table or added a new one you'd like included in project?
       e. Change name of the data model?
    • A. App.config & DataModel.Context.cs file
    • B. In the *.cs file under the DataModel.tt file
    • C. Methods would be under DataModel.Context.cs file
    • D. Import using designer
    • E. DataModel.Context.cs class & constructor
  4. What's the benefit of using Entity Framework?
    Entity Framework (EF) does most of the tedious and heavy lifting associated with datase CRUD commands. In addition, the edmx file, written in XML, gives us to awesome benefits: design time intelli-sense and allows us to error check database functionality at compile time.
  5. What are the suggested names used for the data model, the connection string, and the context string? For example, Leads?
    • LeadModel.edmx
    • LeadConnection
    • LeadContext or LeadEntities
  6. Describe in detail, the steps needed to build a basic Entity Framework console application tied to the Education database WITHOUT using code first, database first, or model first design patterns.
    • 1. Create single solution called Acme.Education
    • 2. Create 4 projects under this solution called: Education.Core, Education.Console, Education.Data, and Education.Model
    • 3. Using NuGet, install EntityFramework on the Data and Console projects
    • 4. Reference each of the other projects as follows:
    •      Model => nothing; 
    •      Data => Model;
    •      Core => Data & Model;
    •      Console => Data & Model;
    • 5. Create basic classes in Model, such as Student.cs or Schedule.cs
    • 6. In Data, configure single class called EducationContext and inherit base DbContext class, create DbSet<Student> and other properties as needed
    • 7. Instantiate the context class and loop through each of the in-memory objects as needed. Make sure to reference the Data and Model namespaces on this page: using Acme.Education.Model;
    • Acme.Education.Data;
  7. What is a repository? Why should we use one?
    A repository pattern is a methodology followed when building out an application which puts an extra layer between the domain classes and the controllers. This abstraction allows the application to be more independent, more manageable, easier to contain (for other developers, say those that are using the UI), more testable, and more maintainable. 

    So USE IT! Because without it, most applications very quickly become very hard to manage and maintain. Think of spaghetti code on steroids. The lack of a good architecture pattern is likely why many applications often fail or because overly complicated and maintainable.
Card Set
OLD Entity Framework & Database First Coding
Questions on Entity Framework and Database First Coding