public List <Department> GetAllDepts() { List <Department> departments = new List <Department>(); using (var db = new ContosoEntities()) { var result = db.GetAllDepartment(); departments = db.Departments.ToList(); foreach (var item in result) { departments.Add(new Department { Id = item.Id, Name = item.Name, Budget = item.Budget, StartDate = item.StartDate, InstructorId = item.InstructorId, RowVersion = item.RowVersion, CreatedDate = item.CreatedDate, CreatedBy = item.CreatedBy, }); } return(departments); } }
public CreateWithBinding() { InitializeComponent(); db = new ContosoEntities(); studentBindingSource.DataSource = new Student(); }
private void button1_Click(object sender, EventArgs e) { using (ContosoEntities db = new ContosoEntities()) { var qry = from s in db.Students select s; dataGridView1.DataSource = qry.ToList(); } }
protected void btn_Save_Click(object sender, EventArgs e) { //conect var conn = new ContosoEntities(); // use the department class to create a new development object Department d = new Department(); //fill the properties of the new department object d.Name = txtName.Text; d.Budget }
private void button2_Click(object sender, EventArgs e) { using (ContosoEntities db = new ContosoEntities()) { var qry = from s in db.Students where s.ID < 5 select new { StudentID = s.ID, SirName = s.LastName }; dataGridView1.DataSource = qry.ToList(); } }
private void button3_Click(object sender, EventArgs e) { using (ContosoEntities db = new ContosoEntities()) { IQueryable <Student> studs = from student in db.Students where student.ID < 5 select student; dataGridView1.DataSource = studs.ToList(); IQueryable <string> names = from student in studs select student.FirstName; listBox1.DataSource = names.ToList(); } }
private void button5_Click(object sender, EventArgs e) { using (ContosoEntities db = new ContosoEntities()) { //navigating from the 'many' to 'one' side var qry = from course in db.Courses where course.Department.Name.ToLower().Equals("mathematics") select course.Title; listBox1.DataSource = qry.ToList(); //Also: //this is the qry to find the HOD responsible for "Calculus" //we can recursively navigate from course entity //see the sql equivalent of this in linqpad! var qry2 = from course in db.Courses where course.Title.Equals("Calculus") select course.Department.Instructor.FirstName; } }
public CreateNoBinding() { InitializeComponent(); db = new ContosoEntities(); }
public Set2Form() { InitializeComponent(); db = new ContosoEntities(); }