private void btnLINQ_Click(object sender, EventArgs e) { var db = new TrainingEntities(); // lấy tất cả các SP là Laptop(id= 1) var query = db.Products.Where(p => p.categoryId == 1); foreach (var item in query) { listBox1.Items.Add(item.productName); } }
private void btnLINQ2_Click(object sender, EventArgs e) { var db = new TrainingEntities(); var query = from P in db.Products where P.categoryId == 1 select new { NameInUpper = P.productName.ToUpper() }; foreach (var item in query) { listBox1.Items.Add(item.NameInUpper); } }
private void btnLINQ1_Click(object sender, EventArgs e) { var db = new TrainingEntities(); var query = from P in db.Products where P.categoryId == 1 select P.productName; // select P foreach (var item in query) { listBox1.Items.Add(item); } }
private void btnJoin_Click(object sender, EventArgs e) { var db = new TrainingEntities(); var query = from Pro in db.Products join Cate in db.categories on Pro.categoryId equals Cate.categoryId select new { Cate.name, Pro.productName }; foreach (var item in query) { listBox1.Items.Add(item.name + " " + item.productName); } }