Example #1
0
        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);
            }
        }
Example #2
0
        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);
            }
        }
Example #3
0
        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);
            }
        }
Example #4
0
        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);
            }
        }