Mock Solution, Framework, & SQL Setup

  1. How do you add SQL Server database connectivity to your project?
    1. Add Microsoft.EntityFrameworkCore or Microsoft.EntityFrameworkCore.SqlServer packages to your project.

    2. Create AppDbContext file with four procedures: constructor, OnModelCreating, and actual DbSet tables.

    3. Open appsettings.json file and enter your database and connection parameters.

    4. Register the database context file (AppDbContext) within the ConfigureServices() procedure of the StartUp.cs class using UseSqlServer() method.
  2. Write the Configuration, Connectivity, SQL, and MVC configurations needed in the Startup.cs file.
    public IConfiguration Configuration { get; }

    • public Startup(IConfiguration configuration)
    • {
    •    Configuration = configuration;
    • }

    • public void ConfigureServices(IServiceCollection services)
    • {
    •    services.AddDbContext<BirthdayDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

    •    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
    • }
  3. Write a connection database string in json. Where is this located?
    It's located in a file called appsettings.json and written in json:

    • "ConnectionStrings": {
    • "DefaultConnection": "server=NOBES-PC\\SQLEXPRESS;Database=Birthday;Trusted_Connection=true;MultipleActiveResultSets=true"
    • }
  4. Write a fully functional database context file (ie, AppDbContext) including constructor, seeding, and DbSet.
    • public class BirthdayDbContext : DbContext
    • {
    • public BirthdayDbContext(DbContextOptions<BirthdayDbContext> options) : base(options) { }

    • protected override void OnModelCreating(ModelBuilder modelBuilder)
    • {
    • modelBuilder.Entity<Canine>().HasData(
    • new Canine { CanineId = 1, Breed = "Chihuahua" },
    • new Canine { CanineId = 2, Breed = "Boxer" },
    • new Canine { CanineId = 3, Breed = "Great Dane"
    • }
    • }


    • public DbSet<GuestResponse> GuestResponses { get; set; }
    • public DbSet<Auto> Autos { get; set; }
    • public DbSet<Canine> Canines { get; set; }
  5. We can use Package Manager to build our new/existing database. What package manager statements can we use for this migration process?
    • Add-Migration MigrationName
    • Remove-Migration
    • Script-Migration
    • Update-Database
    • Update-Database MigrationTarget
  6. What is .NET Core?
    .NET Core is a new software framework developed by Microsoft for C#, Visual Basic, and F#, released in June 2016 with version 2.0 having been released in August 2017.
  7. What are the top .NET Core benefits?
    • Machine independent, can be run not just on Windows machines, but also on Linux, Mac, and more.
    • Smaller, faster applications using a modular approach. Previous .NET applications used the high overhead of the framework which included TONS of unneeded libraries--this modular approach uses ONLY the libraries referenced therefore compiles and runs much quick and is much smaller thereby using less resources.
    • Multiple language support with C#, VB, F# and modern constructs like generics, Language Integrated Query (LINQ), async support and more.
    • Open Source. Runtime, libraries, compiler, languages and tools are all open source on GitHub where contributions are accepted, tested and fully supported.
    • Modern library integration including jQuery, Bootstrap, and GitHub.
    • Designed to build mobile, web, cloud, desktop, gaming, AI, and IoT programs
Card Set
Mock Solution, Framework, & SQL Setup
Questions on entity framework (framework & core) including solution setup, setup of SQL connection string, migration, database creation, and more.