Beispiel #1
0
        static void Main(string[] args)
        {
            //write into SQL database using entity framework
            //Console.WriteLine("Enter employee first name ");
            //string fname = Console.ReadLine();
            //Console.WriteLine("Enter employee last name ");
            //string lname = Console.ReadLine();
            //Console.WriteLine("Enter employee gender ");
            //string gender = Console.ReadLine();
            //Console.WriteLine("Enter employee salary ");
            //int salary = Int32.Parse(Console.ReadLine());
            //Console.WriteLine("Enter department ID ");
            //int deptId = Int32.Parse(Console.ReadLine());

            //using (var context = new CS155Entities())
            //{
            //    var employee = new Employee()
            //    {
            //        FirstName = fname,
            //        LastName = lname,
            //        Gender = gender,
            //        Salary = salary,
            //        DepartmentId = deptId

            //    };
            //    context.Employees.Add(employee);
            //    context.SaveChanges();
            //}

            //Reading from SQL database using entity framework
            using (var context = new CS155Entities())
            {
                foreach (var emp in context.Employees)
                {
                    Console.Write(" " + emp.FirstName + "    " + emp.LastName + "   " + emp.Gender + "  " + emp.Salary + "  " + emp.Department.Name);
                    Console.WriteLine();
                }
                ;
                Console.ReadKey();
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //writing into sql database
            //Console.WriteLine("Enter employee first name");
            //string fname = Console.ReadLine();
            //Console.WriteLine("Enter employee last name");
            //string lname = Console.ReadLine();
            //Console.WriteLine("Enter employee gender");
            //string gender = Console.ReadLine();
            //Console.WriteLine("Enter employee Salary");
            //int salary = Int32.Parse(Console.ReadLine());
            //Console.WriteLine("Enter employee ID name");
            //int departmentId = Int32.Parse(Console.ReadLine());

            //using (var context = new CS155Entities())
            //{
            //    var employee = new Employee()
            //    {
            //        FirstName = "Red",
            //        LastName = "Foreman",
            //        Gender = "Male",
            //        Salary = 5000,
            //        DepartmentId = 2
            //    };
            //    context.Employees.Add(employee);
            //    context.SaveChanges();
            //}


            // reading a sql database
            using (var context = new CS155Entities())
            {
                foreach (var emp in context.Employees)
                {
                    Console.WriteLine($"{emp.FirstName}     {emp.LastName}     {emp.Gender}      {emp.Salary}      {emp.DepartmentId}");
                }
            }
        }