Creating RestfulAPI project With EF Core in Blazor Project

“ConnectionStrings”: {“DBConnection”: “server=(localdb)\\DESKTOP-UPBRTCM;database=EmployeeDB;Trusted_Connection=true”},
- Microsoft.EntityFrameworkCore.SqlServer- Microsoft.EntityFrameworkCore.Tools
DBContext Class
using Microsoft.EntityFrameworkCore;using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;namespace EmployeeManagement.API.Model{public class AppDbContext:DbContext{public AppDbContext(DbContextOptions<AppDbContext> options): base(options){}public DbSet<Employee> Employees { get; set; }public DbSet<Department> Departments { get; set; }protected override void OnModelCreating(ModelBuilder modelBuilder){base.OnModelCreating(modelBuilder);//Seed Departments TablemodelBuilder.Entity<Department>().HasData(new Department { DepartmentId = 1, DepartmentName = “IT” });modelBuilder.Entity<Department>().HasData(new Department { DepartmentId = 2, DepartmentName = “HR” });// Seed Employee TablemodelBuilder.Entity<Employee>().HasData(new Employee{EmployeeId = 1,FirstName = “Vaibhav”,LastName = “Bhapkar”,Email = “”,DateOfBrith = new DateTime(1990, 10, 5),Gender = Gender.Male,DepartmentId = 1,PhotoPath = “images/vaibhav.png”});}}}
public void ConfigureServices(IServiceCollection services){services.AddDbContext<AppDbContext>(options => options.UseSqlServer(“DBConnection”));services.AddControllers();}
- First Step here to execute Add-Migration InitialCreateOpen package manager console by click on Tools-> NuGet package -> Package ConsolePM> Add-Migration InitialCreateMultiple startup projects set.Using project ‘EmployeeManagement.API’ as the startup project.Build started…Build succeeded.To undo this action, use Remove-Migration.- Next step is to execute Update-Database commandPM>UpdateDatabaseBuild started…Build succeeded.Done



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vaibhav Bhapkar

Vaibhav Bhapkar

Technical Speaker | Computer Engineer | Full Stack Web Developer | ML Enthusiast | * Knowledge Shared = Knowledge² *