示例#1
0
        private void fromEmployeeList_Load(object sender, EventArgs e)
        {
            List <Employee> employees = null;
            DataSet         ds        = new DataSet();

            using (TestEntities testEntities = new TestEntities())
            {
                employees = (from employeeRecs in testEntities.Employees
                             select employeeRecs).ToList();
            }

            dataGridView1.DataSource = employees;
        }
 private void Save_Click(object sender, EventArgs e)
 {
     using (TestEntities testEntities = new TestEntities())
     {
         Employee emp = new Employee()
         {
             Id     = 1,
             Name   = "Ramesh",
             Age    = 38,
             Gender = "Male"
         };
         try
         {
             testEntities.Employees.Add(emp);
             testEntities.SaveChanges();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }