Learning ASP.NET Core MVC Programming by Mugilan T. S. Ragupathi

Learning ASP.NET Core MVC Programming by Mugilan T. S. Ragupathi

Author:Mugilan T. S. Ragupathi [Ragupathi, Mugilan T. S.]
Language: eng
Format: mobi
Publisher: Packt Publishing
Published: 2016-11-16T05:00:00+00:00


Create Models and DbContext classes.

Create the Models folder and add the Employee model class and EmployeeDbContext class.

Create the Employee Model class (Employee.cs in the Models folder):public class Employee { public int EmployeeId { get; set; } public string Name { get; set; } public string Designation { get; set; } public decimal Salary { get; set; } }

Create EmployeeDbContext (EmployeeDbContext.cs in the Models folder):using Microsoft.Data.Entity; using Microsoft.Extensions.Configuration; namespace Validation.Models { public class EmployeeDbContext : DbContext { public IConfigurationRoot Configuration { get; set; } public DbSet<Employee> Employees { get; set; } public EmployeeDbContext() { var builder = new ConfigurationBuilder() .AddJsonFile("config.json") .AddEnvironmentVariables(); Configuration = builder.Build(); } protected override void OnConfiguring (DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer (Configuration.Get<string> ("Data:DefaultConnection:ConnectionString")); base.OnConfiguring(optionsBuilder); } } }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.