static void _Nested_UpdateReaders_Employees( IKLink link ) { var cmd = link.Update( x => x.Employees ) .Where( x => x.CountryId == "es" ) .Column( x => x.CountryId = "es#" ); DEBUG.IndentLine( "\n> Command => {0}", cmd ); foreach( var emp in cmd.ConvertBy( rec => { EmployeeTable table = new EmployeeTable(); dynamic d = rec; table.Id = d.Id; table.FirstName = d.FirstName; table.LastName = d.LastName; table.CountryId = d.CountryId; return table; } ) ) DEBUG.WriteLine( "\n> Employee => {0}", emp ); cmd.Dispose(); DEBUG.Unindent(); }
public static void Nested_UpdateReaders( IKLink link ) { Console.WriteLine( "\n===== Nested Updates..." ); KCommandRaw raw = link.Raw(); Console.WriteLine( "\n== SUSPENDING THE CONSTRAINTS..." ); raw.Set( "ALTER TABLE Countries NOCHECK CONSTRAINT ALL" ); raw.Execute(); raw.Set( "ALTER TABLE Employees NOCHECK CONSTRAINT ALL" ); raw.Execute(); var cmd = link.Update( x => x.Countries ) .Where( x => x.Id == "es" ) .Column( x => x.Id = "es#" ); Console.WriteLine( "\n> Command => {0}", cmd ); foreach( var ctry in cmd.ConvertBy( rec => { CountryTable table = new CountryTable(); dynamic d = rec; table.Id = d.Id; table.Name = d.Name; table.RegionId = d.RegionId; _Nested_UpdateReaders_Employees( link ); return table; } ) ) Console.WriteLine( "\n> Country => {0}", ctry ); cmd.Dispose(); Console.WriteLine( "\n== REACTIVATING THE CONSTRAINTS..." ); raw.Set( "ALTER TABLE Countries CHECK CONSTRAINT ALL" ); raw.Execute(); raw.Set( "ALTER TABLE Employees CHECK CONSTRAINT ALL" ); raw.Execute(); }
public static void Test_Scenario( IKLink link ) { Console.WriteLine( "\n===== Cleaning the scenario ...[Enter]" ); Console.ReadLine(); link.Delete( x => x.Employees ).Execute(); link.Delete( x => x.Countries ).Execute(); link.Delete( x => x.Regions ).Execute(); Console.WriteLine( "\n===== Persisting the hierarchy through a leaf object...[Enter]" ); Console.ReadLine(); Region rEMEA = new Region() { Id = "200", Name = "EMEA" }; Region rNE = new Region() { Id = "210", Name = "North Europe", Parent = rEMEA }; Country cUK = new Country() { Id = "uk", Name = "United Kingdom", Region = rNE }; Employee eM = new Employee() { Id = "M", Country = cUK, FirstName = "M" }; Employee e007 = new Employee() { Id = "007", Country = cUK, FirstName = "James", LastName = "Bond", Manager = eM }; e007.BirthDate = new CalendarDate( 1940, 1, 1 ); e007.Active = true; e007.JoinDate = new CalendarDate( 1965, 1, 1 ); e007.StartTime = new ClockTime( 8, 0, 0 ); e007.Photo = new byte[] { 0, 0, 7 }; e007 = link.Insert( e007 ).Execute(); Console.WriteLine( "\n>> Region EMEA: {0}", rEMEA ); Console.WriteLine( "\n>> Region North Europe: {0}", rNE ); Console.WriteLine( "\n>> Country UK: {0}", cUK ); Console.WriteLine( "\n>> Employee M: {0}", eM ); Console.WriteLine( "\n>> Employee 007: {0}", e007 ); Console.WriteLine( "\n===== Creating another set ...[Enter]" ); Console.ReadLine(); Region rAMS = new Region() { Id = "100", Name = "Americas" }; link.Insert( rAMS ).Execute(); Region rNA = new Region() { Id = "110", Name = "North America", Parent = rAMS }; link.Insert( rNA ).Execute(); Console.WriteLine( "\n> Inserted theatre: {0}", rAMS ); Country cUSA = new Country() { Id = "us", Name = "United States of America", Region = rNA }; Employee e009 = new Employee() { Id = "009", FirstName = "John", LastName = "Smith", Country = cUSA }; e009 = link.Insert( e009 ).Execute(); Console.WriteLine( "\n> Inserted spy: {0}", e009 ); Console.WriteLine( "\n===== An update with change in the key columns ...[Enter]" ); Console.ReadLine(); e009.Country = cUK; e009 = link.Update( e009 ).Execute(); cUSA.Employees.Remove( e009 ); link.Update( cUSA ).Execute(); Console.WriteLine( "\n> Updated spy: {0}", e009 ); Console.WriteLine( "\n>> UK Employees: {0}", TypeHelper.ToString( cUK.Employees ) ); Console.WriteLine( "\n>> USA Employees: {0}", TypeHelper.ToString( cUSA.Employees ) ); Console.WriteLine( "\n===== Removing by cascading deletion ...[Enter]" ); Console.ReadLine(); link.Delete( rEMEA ).Execute(); link.Delete( rAMS).Execute(); }
public static void Update_Enumerate( IKLink link ) { Console.WriteLine( "\n===== Update enumerating the results..." ); var cmd = link.Update( x => x.Employees ) .Where( x => x.FirstName >= "E" ) .Column( x => x.ManagerId = null, x => x.LastName = x.LastName + "_1", x => x.Photo = new byte[] { 99, 98, 97, 96 } ); Console.WriteLine( "\n> Command => {0}", cmd ); foreach( var obj in cmd ) Console.WriteLine( "\n> Record => {0}", obj ); cmd.Dispose(); }
public static void Test_Update( IKLink link, Region reg ) { Console.WriteLine( "\n===== Updating a region ..." ); Console.ReadLine(); reg.Name = "New Name"; reg = link.Update( reg ).Execute(); Console.WriteLine( "\n>> Updated Region: {0}", reg ); }