Пример #1
0
        public static void Task2_2()
        {
            using (var db = new DbNorthwind())
            {
                LinqToDB.Common.Configuration.Linq.AllowMultipleQuery = true;

                var territories =
                    (
                        from e in db.Employee
                        select e.GetTerritories()
                    ).ToList();

                for (int i = 0; i < territories.Count; i++)
                {
                    territories[i] = territories[i].ToList();
                }

                var employees =
                    (
                        from e in db.Employee
                        select e
                    ).ToList();

                for (int i = 0; i < territories.Count; i++)
                {
                    Console.WriteLine($"{employees[i].LastName}: {string.Join(",", territories[i])}");
                }
                Console.WriteLine();
            }
        }
Пример #2
0
        public static void Task3_1()
        {
            int employeeID = 13321;

            using (var db = new DbNorthwind())
            {
                db.Execute("SET IDENTITY_INSERT EMPLOYEES ON");

                db.Employee.InsertWithIdentity(
                    () => new Employee()
                {
                    ID        = employeeID,
                    FirstName = "Test",
                    LastName  = "User"
                });

                db.EmployeeTerritory.Insert(
                    () => new EmployeeTerritory()
                {
                    EmployeeID  = employeeID,
                    TerritoryID = "01581"
                });

                db.EmployeeTerritory.Insert(
                    () => new EmployeeTerritory()
                {
                    EmployeeID  = employeeID,
                    TerritoryID = "01730"
                });
            }
        }
Пример #3
0
 public static List <Product> Task2_1()
 {
     using (var db = new DbNorthwind())
     {
         var query = db.Product.LoadWith(p => p.Category).LoadWith(p => p.Supplier);
         return(query.ToList());
     }
 }
Пример #4
0
 static void Main(string[] args)
 {
     PrintCollection(DbNorthwind.Task2_1());
     DbNorthwind.Task2_2();
     DbNorthwind.Task2_3();
     DbNorthwind.Task3_1();
     DbNorthwind.Task3_2();
     Console.ReadLine();
 }
Пример #5
0
 public static void Task3_2()
 {
     using (var db = new DbNorthwind())
     {
         db.Product
         .Where(p => p.Name == "Chai")
         .Set(p => p.CategoryID, 2)
         .Update();
     }
 }
Пример #6
0
        public static void Task2_3()
        {
            using (var db = new DbNorthwind())
            {
                LinqToDB.Common.Configuration.Linq.AllowMultipleQuery = true;
                var employees =
                    (
                        from t in db.Territory
                        select t.GetEmployees().Count()
                    ).ToList();

                var territories =
                    (
                        from r in db.Territory
                        select r
                    ).ToList();

                for (int i = 0; i < territories.Count; i++)
                {
                    Console.WriteLine($"{territories[i].Description}: {employees[i]}");
                }
            }
        }