public class Employee { public int ID { get; set; } public string fname { get; set; } public string lastname { get; set; } public decimal? salary { get; set; } public virtual Department department { get; set; } public string address { get; set; } [EmailAddress] [DefaultValue("ahmet@yahoo.com")] public string? email { get; set; } [Range(18, 60)] public int age { get; set; } } public class Department { public int DepartmentID { get; set; } public string name { get; set; } public int yearofcreation { get; set; } public ICollection employees { get; set; } = new HashSet(); } [Table("courses")] public class TrainingCourse { [Key] public int coursenumber { get; set; } [Required] [MaxLength(50)] public string coursetitle { get; set; } [Column("duration", TypeName = "int")] public short courseduration { get; set; } [Required] public string courseurl { get; set; } public virtual ICollection Employees { get; set; } = new HashSet(); public virtual ICollection courseEmployees { get; set; } } using (mydbcontext context=new mydbcontext())//using()block for disbosing(removing unmanged resource) { Department dp1=new Department(){name="engineering"}; Department dp2=new Department(){name="Hr"}; Employee emp=new Employee(){fname="ahmed",lastname="eid",address="alex"}; context.Departments.Add(dp1);//or context.Add(dp2); context.Add(course); context.Employees.Add(emp); context.SaveChanges(); Console.WriteLine(dp1.name); var results=context.Departments.Where(d=>d.name=="Hr"); Department d=results.FirstOrDefault(); }