using Microsoft.EntityFrameworkCore; namespace WebApi.Model { public class EmployeeContext : DbContext // Inherit { // Constructor #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public EmployeeContext(DbContextOptions<employeecontext> options) : base(options) // DI #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. { } // DataSet Property of the Classes public DbSet<tblemployee> TblEmployee { get; set; } public DbSet<tbldesignation> TblDesignation { get; set; } } }
using Microsoft.EntityFrameworkCore; using WebApi.Model; namespace WebApi { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddDbContext<employeecontext>(db => db.UseSqlServer(Configuration.GetConnectionString("ConEmp"))); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if(env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } } }
public EmployeeContext(DbContextOptions<employeecontext> options)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)