Add tables to Existing Database using Code First approach in Entity Framework in Windows Application

smile
 
on Jun 24, 2021 10:11 PM
869 Views

I want to generate more than 5 tables using Code First Approach in Entity Framework in windows form.

Tables details are following.

1-tblPatient

PID, P_Name,DID,R_Date,Is_Active 

2-tblDoctor

DID, D_Name, RID 

3-tblRoom

RID, R_Name 

4-tblDoctorCall

CID,D_Name,P_Name,Is_Active,C_Date

5-tblUser

UID, U_Name,U_Pass,U_Type,DID

I have made a Test.cs like that 

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace myApp
{
    public class Patient
    {
        //scalar
        [Key]
        public int PId { get; set; }
        [StringLength(255)]
        public string PName { get; set; }
         [StringLength(255)]
        public DateTime? R_Date { get; set; }
        public bool Is_Active { get; set; }
        public int ObjectState { get; set; }

        //reference navigation
        public int DId { get; set; }
        public Grade D_Name { get; set; }

    }

    public class Doctor
    {
        [Key]
        public int DId { get; set; }
        [StringLength(255)]
        public string D_Name { get; set; }
        [NotMapped]
        public int ObjectState { get; set; }
        public ICollection<Patient> Patient { get; set; }
    }    
}

and ModelContext is  

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace myApp
{
    public class ModelContext : DbContext
    {
        public ModelContext() : base("name=cn") { }
        //classes become entities when included as 
        public DbSet<Patient> Students { get; set; }
        public DbSet<Doctor> Grades { get; set; }        
    }    
}

pls guide me how to add more table with primary and foriegn key relationship.

there are 3 tables missing as per above mention 5 tables.

Download FREE API for Word, Excel and PDF in ASP.Net: Download