Example #1
0
        public void Nested_Updates_And_Suspending_Constrains()
        {
            DB.Prepare();

            DB.Link.Raw("ALTER TABLE Countries NOCHECK CONSTRAINT ALL").Execute();
            DB.Link.Raw("ALTER TABLE Employees NOCHECK CONSTRAINT ALL").Execute();

            var cmdCtry = DB.Link
                          .Update(x => x.Countries)
                          .Where(x => x.Id == "es")
                          .Columns(
                x => x.Id = "es#");

            ConsoleEx.WriteLine("\n> Command: {0}", cmdCtry);

            foreach (DataDB.Country ctry in cmdCtry.ConvertBy(recCtry =>
            {
                ConsoleEx.WriteLine("\n\t- Country: {0}", recCtry);

                dynamic dinCtry = recCtry;
                DataDB.Country objCtry = new DataDB.Country();
                objCtry.Id = dinCtry.Id;
                objCtry.Name = dinCtry.Name;
                objCtry.RegionId = dinCtry.RegionId;

                var cmdEmp = DB.Link
                             .Update(x => x.Employees)
                             .Where(x => x.CountryId == "es")
                             .Columns(
                    x => x.CountryId = "es#");

                ConsoleEx.WriteLine("\n\t> Command: {0}", cmdEmp);

                foreach (DataDB.Employee emp in cmdEmp.ConvertBy(recEmp =>
                {
                    ConsoleEx.WriteLine("\n\t\t- Employee: {0}", recEmp);

                    dynamic dinEmp = recEmp;
                    DataDB.Employee objEmp = new DataDB.Employee();
                    objEmp.Id = dinEmp.Id; objEmp.BirthDate = dinEmp.BirthDate;
                    objEmp.FirstName = dinEmp.FirstName; objEmp.LastName = dinEmp.LastName;
                    objEmp.ManagerId = dinEmp.ManagerId; objEmp.CountryId = dinEmp.CountryId;

                    return(objEmp);
                }))
                {
                    ;
                }

                return(objCtry);
            }))
            {
                ;
            }

            DB.Link.Raw("ALTER TABLE Countries CHECK CONSTRAINT ALL").Execute();
            DB.Link.Raw("ALTER TABLE Employees CHECK CONSTRAINT ALL").Execute();

            DB.IsPrepared = false;
        }
Example #2
0
        public void Query_With_Complex_And_Nested_Conversion()
        {
            DB.Prepare();

            var cmdCtry = DB.Link.From(x => x.Countries.As(x.Ctry));

            ConsoleEx.WriteLine("\n> Command: {0}", cmdCtry);

            foreach (DataDB.Country ctry in cmdCtry.ConvertBy(recCtry =>
            {
                ConsoleEx.WriteLine("\n- Country: {0}", recCtry);

                dynamic dinCtry = recCtry;
                DataDB.Country objCtry = new DataDB.Country();
                objCtry.Id = dinCtry.Id;
                objCtry.Name = dinCtry.Name;
                objCtry.RegionId = dinCtry.RegionId;

                var cmdEmp = DB.Link.From(x => x.Employees).Where(x => x.CountryId == objCtry.Id);
                ConsoleEx.WriteLine("\n\t> SubCommand: {0}", cmdEmp);

                foreach (DataDB.Employee emp in cmdEmp.ConvertBy(recEmp =>
                {
                    ConsoleEx.WriteLine("\n\t\t- Employee: {0}", recEmp);

                    dynamic dinEmp = recEmp;
                    DataDB.Employee objEmp = new DataDB.Employee();
                    objEmp.Id = dinEmp.Id; objEmp.BirthDate = dinEmp.BirthDate;
                    objEmp.FirstName = dinEmp.FirstName; objEmp.LastName = dinEmp.LastName;
                    objEmp.ManagerId = dinEmp.ManagerId; objEmp.CountryId = dinEmp.CountryId;

                    return(objEmp);
                }))
                {
                    ;
                }

                return(objCtry);
            }))
            {
                ;
            }
        }
		public void Query_With_Complex_And_Nested_Conversion()
		{
			DB.Prepare();

			var cmdCtry = DB.Link.From(x => x.Countries.As(x.Ctry));
			ConsoleEx.WriteLine("\n> Command: {0}", cmdCtry);

			foreach (DataDB.Country ctry in cmdCtry.ConvertBy(recCtry =>
			{
				ConsoleEx.WriteLine("\n- Country: {0}", recCtry);

				dynamic dinCtry = recCtry;
				DataDB.Country objCtry = new DataDB.Country();
				objCtry.Id = dinCtry.Id;
				objCtry.Name = dinCtry.Name;
				objCtry.RegionId = dinCtry.RegionId;

				var cmdEmp = DB.Link.From(x => x.Employees).Where(x => x.CountryId == objCtry.Id);
				ConsoleEx.WriteLine("\n\t> SubCommand: {0}", cmdEmp);

				foreach (DataDB.Employee emp in cmdEmp.ConvertBy(recEmp =>
				{
					ConsoleEx.WriteLine("\n\t\t- Employee: {0}", recEmp);

					dynamic dinEmp = recEmp;
					DataDB.Employee objEmp = new DataDB.Employee();
					objEmp.Id = dinEmp.Id; objEmp.BirthDate = dinEmp.BirthDate;
					objEmp.FirstName = dinEmp.FirstName; objEmp.LastName = dinEmp.LastName;
					objEmp.ManagerId = dinEmp.ManagerId; objEmp.CountryId = dinEmp.CountryId;

					return objEmp;
				})) ;

				return objCtry;
			})) ;
		}
		public void Nested_Updates_And_Suspending_Constrains()
		{
			DB.Prepare();

			DB.Link.Raw("ALTER TABLE Countries NOCHECK CONSTRAINT ALL").Execute();
			DB.Link.Raw("ALTER TABLE Employees NOCHECK CONSTRAINT ALL").Execute();

			var cmdCtry = DB.Link
				.Update(x => x.Countries)
				.Where(x => x.Id == "es")
				.Columns(
					x => x.Id = "es#");

			ConsoleEx.WriteLine("\n> Command: {0}", cmdCtry);

			foreach (DataDB.Country ctry in cmdCtry.ConvertBy(recCtry =>
			{
				ConsoleEx.WriteLine("\n\t- Country: {0}", recCtry);

				dynamic dinCtry = recCtry;
				DataDB.Country objCtry = new DataDB.Country();
				objCtry.Id = dinCtry.Id;
				objCtry.Name = dinCtry.Name;
				objCtry.RegionId = dinCtry.RegionId;

				var cmdEmp = DB.Link
					.Update(x => x.Employees)
					.Where(x => x.CountryId == "es")
					.Columns(
						x => x.CountryId = "es#");

				ConsoleEx.WriteLine("\n\t> Command: {0}", cmdEmp);

				foreach (DataDB.Employee emp in cmdEmp.ConvertBy(recEmp =>
				{
					ConsoleEx.WriteLine("\n\t\t- Employee: {0}", recEmp);

					dynamic dinEmp = recEmp;
					DataDB.Employee objEmp = new DataDB.Employee();
					objEmp.Id = dinEmp.Id; objEmp.BirthDate = dinEmp.BirthDate;
					objEmp.FirstName = dinEmp.FirstName; objEmp.LastName = dinEmp.LastName;
					objEmp.ManagerId = dinEmp.ManagerId; objEmp.CountryId = dinEmp.CountryId;

					return objEmp;
				})) ;

				return objCtry;
			})) ;

			DB.Link.Raw("ALTER TABLE Countries CHECK CONSTRAINT ALL").Execute();
			DB.Link.Raw("ALTER TABLE Employees CHECK CONSTRAINT ALL").Execute();

			DB.IsPrepared = false;
		}