Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.8 kB
3
Indexable
Never
public static void grouping (){
            //query
            
            var fullMaDia = from p in dbs.T_Dia_Phims select p.MaDia;
            Console.WriteLine("bang ma dia:");
            foreach (var p in fullMaDia)
            {
                Console.WriteLine(p);

            }
            Console.WriteLine("===============================================");
            var maDiaGroupBy = from p in dbs.T_Dia_Phims group p by p.T_Dia;
            Console.WriteLine("Group by theo ma dia:");
            foreach(var g in maDiaGroupBy)
            { 
                Console.WriteLine(g.Key.MaDia+"\t"+g.Key.TenDia);
                
            }
        }
        public static void aggregate()
        {
            var phimCounts =
                     from p in dbs.T_Phim_DienViens
                     group p by p.MaDienVien into p
                     select new
                     {
                         MaDV = p.Key,
                         soLuongPhimDong = p.Key.Count()
                     };
            foreach (var p in phimCounts)
            {
                Console.WriteLine(p);
            }
        }
        public static void conversion()
        {

            var DV = from p in dbs.T_DienViens select p;
            Console.WriteLine("bang dien vien:");
            foreach (var p in DV)
            {
                Console.WriteLine(p.MaDienVien + "\t" + p.TenDienVien);
            }
            Console.WriteLine("=======================================================");
            var sortNameDV =
                    from p in dbs.T_DienViens
                    orderby p.TenDienVien
                    select p;
            Console.WriteLine("sau khi sap xep theo bang chu cai:");
            foreach (var p in sortNameDV)
            {
                Console.WriteLine(p.MaDienVien+"\t"+p.TenDienVien);
            }
        }
        public static void ElementOperator()
        {
            var DV = from p in dbs.T_DienViens select p;
            Console.WriteLine("bang dien vien:");
            foreach (var p in DV)
            {
                Console.WriteLine(p.MaDienVien + "\t" + p.TenDienVien+"\t"+p.QuocTich);
            }
            Console.WriteLine("=======================================================");
            Console.WriteLine("quoc tich VN dau tien");
            var fulllVN =
                    from p in dbs.T_DienViens
                    where p.QuocTich == "Việt Nam"
                    select p;
            var VNfirst= fulllVN.FirstOrDefault(); //lấy phần tử có quốc tịch VN đầu tiên khi query
            Console.WriteLine(VNfirst.MaDienVien+"\t"+VNfirst.TenDienVien+"\t"+VNfirst.QuocTich);
            Console.WriteLine("=======================================================");
            Console.WriteLine("quoc tich my dau tien");
            var fulllMy =
                    from p in dbs.T_DienViens
                    where p.QuocTich == "Mỹ"
                    select p;
            var Myfirst = fulllMy.FirstOrDefault(); //lấy phần tử có quốc tịch Mỹ đầu tiên khi query
            Console.WriteLine(Myfirst.MaDienVien + "\t" + Myfirst.TenDienVien + "\t" + Myfirst.QuocTich);
        }
        public  static void joinOpeator()
        {
            var customJoin = from p in dbs.T_ThueDias
                              join g in dbs.T_KhachHangs on p.MaKhachHang equals g.MaKhachHang
                              select new { maKH = p.MaKhachHang, tenKH = g.TenKhachHang, diaChi = g.DiaChi, diaThue = p.MaDia };
            foreach (var p in customJoin)
            {
                Console.WriteLine(p);
            }

        }