public static Region Test_Insert( IKLink link ) { Console.WriteLine( "\n===== Inserting a region ..." ); Console.ReadLine(); Region reg = new Region() { Id = "XXX", ParentId = "200" }; reg = link.Insert( reg ).Execute(); Console.WriteLine( "\n>> Inserted Region: {0}", reg ); return reg; }
public static void Insert_JamesBond_Enumerate( IKLink link ) { Console.WriteLine( "\n===== Insert James Bond enumerating the results..." ); var cmd = link.Insert( x => x.Employees ).Column( x => x.Id = "007", x => x.FirstName = "James", x => x.LastName = "Bond", x => x.CountryId = "uk", x => x.JoinDate = null, x => x.Photo = new byte[] { 0, 0, 7 } ); Console.WriteLine( "\n> Command => {0}", cmd ); foreach( var obj in cmd ) Console.WriteLine( "\n> Record => {0}", obj ); cmd.Dispose(); }
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 Employee Test_Insert( IKLink link ) { Console.WriteLine( "\n===== Insert..." ); Country ctry = link.Find<Country>( x => x.Id == "us" ); Employee manager = link.Find<Employee>( x => x.Id == "E2001" ); Employee emp = new Employee() { Id = "007", FirstName = "James", LastName = "Bond", Country = ctry, Manager = manager }; emp = link.Insert( emp ).Execute(); PrintEmployee( null, emp, 0 ); return emp; }