Posts

Showing posts from November, 2024

Code First Method in C# .NET 8 Entity Framework Core

Image
There are 3 approach to deploy data from database to api One is Code First.in here we first create data model and create and update database later   Create Project with Employee Controller Here we create the Data Model  public class Employee_Personal { [Key]     public int Id { get; set; } [Required] [MaxLength(50)] public string Employee_First_Name{ get; set; } [Required] [MaxLength(50)] public string Employee_Last_Name { get; set; } [Required] public DateTime DOB{ get; set; } [Required] [MaxLength(30)] public string Position { get; set; } } Then get the connection string  from  App setting json  and Inject to Program.cs class here is connection string  "ConnectionStrings": {   "ConStrEmp": "Server=LAPTOP-2OTFH16P\\SQLEXPRESS;Database=EmployeeDb;User Id=sa;password=123;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True;" },  here is how to add Program.cs class builder.Services....