Posts

Showing posts from October, 2024
Image
  Create Context class optional constructor in fly   Go to Visual Studio 2022 and Right click on the project Add->Class     give a Name  as ContactDbContext   Inherit it   from     DbContext                       Then right click on the class name Proess Ctrl + (.)Period Symbol select Generate Constructor 'ContactDbContext(options)' Format:Contrctuctor 'ClassName(options)' then it will create a optional constructor automatically   you can press ctor snippet to auto generate primary constructor here is the video link https://www.youtube.com/watch?v=zUDN5MzQuj8

Create Web Api with Entity Framework Core DB First

Image
DBFirst Approach always create database first and then automatically create model from db First Create Database and Create Table with Any Name       Eg:EmployeePersonalData                Then  go to appsettings.json and put the connection string                     "ConStr": "Server=LAPTOP-2OTFH16P\\SQLEXPRESS;Database=EmployeeDb;User Id=sa;password=123;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True;" Server: SQL server Name Database:Db Name Trusted_Connection need for HTTPS TrustServerCertificate=True also compulsory for HTTPS Then Right Click on Nuget Packages and install below packages below 3 packages are compulsory and should be same version and stable version              Microsoft.EntityFrameworkCore Microsoft.EntityFrameworkCore.SqlServer Microsoft.EntityFrameworkCore.Tools Then Execute...