Beispiel #1
0
		public static void Test_Cache_Unicity( IKLink link, Region reg )
		{
			Console.WriteLine( "\n===== Testing unicity of the cache..." ); Console.ReadLine();
			Region neo = link.Find<Region>( x => x.Id == reg.Id );
			Console.WriteLine( "\n> New Region: {0}", neo );
			Console.WriteLine( "\n>> Same entity?: {0}", object.ReferenceEquals( reg, neo ) );
		}
Beispiel #2
0
		public static Region Test_FindRegion( IKLink link, string id )
		{
			Console.WriteLine( "\n===== Finding a given region..." ); Console.ReadLine();
			Region reg = link.Find<Region>( x => x.Id == id );
			Console.WriteLine( "\n> Found Region: {0}", reg );
			return reg;
		}
		public static void Test_Delete_Cascading( IKLink link )
		{
			Console.WriteLine( "\n===== Delete All by Cascading ..." );
			Region reg = link.Find<Region>( x => x.Id == "000" );
			reg = link.Delete( reg ).Execute();

			Console.WriteLine( "\n>> Region: {0}", reg == null ? "<null>" : reg.ToString() );
		}
		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;
		}
		public static void Test_Find_SingleRegion( IKLink link )
		{
			Console.WriteLine( "\n===== Find single Region ..." );
			Region reg = link.Find<Region>( x => x.Id = "200" );

			Console.WriteLine( "\n===== Printing Regions ..." );
			int level = 0;
			PrintRegion( null, reg, level );
		}
		public static void Test_Find_SingleCountry( IKLink link )
		{
			Console.WriteLine( "\n===== Find single Country ..." );
			Country ctry = link.Find<Country>( x => x.Id = "es" );

			Console.WriteLine( "\n===== Printing Countries ..." );
			int level = 0;
			PrintCountry( null, ctry, level );
		}
		public static void Test_Find_SingleEmployee( IKLink link )
		{
			Console.WriteLine( "\n===== Find single Employee ..." );
			Employee emp = link.Find<Employee>( x => x.Id = "1001" );

			Console.WriteLine( "\n===== Printing Employees ..." );
			int level = 0;
			PrintEmployee( null, emp, level );
		}
		public static KMap<Employee> CreateMapEmployee( IKLink link )
		{
			var map = new KMap<Employee>( link, x => x.Employees );
			map.UnManagedColumns( "ManagerId", "CountryId" );

			map.CreateInstance = () => { return new Employee(); };
			map.ClearInstance = obj => { obj.Clear(); };

			map.WriteRecord = ( obj, record ) => {
				DEBUG.IndentLine( "\n-- Map<Employee>.WriteRecord() Instance = {0}", obj );
				map.BaseWriteRecord( obj, record );
				record.OnSet( "ManagerId", () => { return obj.Manager == null ? null : obj.Manager.Id; } );
				record.OnSet( "CountryId", () => { return obj.Country == null ? null : obj.Country.Id; } );
				DEBUG.Unindent();
			};
			map.LoadRecord = ( record, obj ) => {
				DEBUG.IndentLine( "\n-- Map<Employee>.LoadRecord() Record = {0}", record );
				map.BaseLoadRecord( record, obj );
				record.OnGet( "ManagerId", val => { obj.Manager = val == null ? null : link.Find<Employee>( x => x.Id == val ); } );
				record.OnGet( "CountryId", val => { obj.Country = val == null ? null : link.Find<Country>( x => x.Id == val ); } );
				DEBUG.Unindent();
			};
			map.OnRefresh = obj => {
				DEBUG.IndentLine( "\n-- Map<Employee>.OnRefresh() Instance = {0}", obj );
				obj = map.BaseOnRefresh( obj );
				obj.Employees.Clear(); obj.Employees.AddRange( link.Query<Employee>().Where( x => x.ManagerId == obj.Id ).ToList() );
				DEBUG.Unindent(); return obj;
			};

			map.OnInsert = obj => {
				DEBUG.IndentLine( "\n-- Map<Employee>.OnInsert() Instance = {0} ...", obj );
				obj.Manager = link.Sync( obj.Manager, KMaps.SyncReason.Insert );
				obj.Country = link.Sync( obj.Country, KMaps.SyncReason.Insert );
				obj = map.BaseOnInsert( obj );
				link.Sync<Employee>( obj.Employees, KMaps.SyncReason.Insert );
				DEBUG.Unindent(); return obj;
			};
			map.OnUpdate = obj => {
				DEBUG.IndentLine( "\n-- Map<Employee>.OnUpdate() Instance = {0} ...", obj );
				obj.Manager = link.Sync( obj.Manager, KMaps.SyncReason.Update );
				obj.Country = link.Sync( obj.Country, KMaps.SyncReason.Update );
				obj = map.BaseOnUpdate( obj );
				link.Sync<Employee>( obj.Employees, KMaps.SyncReason.Update );
				DEBUG.Unindent(); return obj;
			};
			map.OnDelete = obj => {
				DEBUG.IndentLine( "\n-- Map<Employee>.OnDelete() Instance = {0} ...", obj );
				link.Sync<Employee>( obj.Employees, KMaps.SyncReason.Delete );
				obj = map.BaseOnDelete( obj );
				DEBUG.Unindent(); return obj;
			};

			map.Validate();
			Console.WriteLine( "\n> Map: {0} -- Discarded: {1} -- Schema: {2}",
				map, TypeHelper.ToString( map.DiscardedColumns, "[]" ), map.Schema );
			return map;
		}
		public static KMap<Country> CreateMapCountry( IKLink link )
		{
			var map = new KMap<Country>( link, x => x.Countries );
			map.UnManagedColumns( "RegionId" );

			map.CreateInstance = () => { return new Country(); };
			map.ClearInstance = obj => { obj.Clear(); };

			map.WriteRecord = ( obj, record ) => {
				DEBUG.IndentLine( "\n-- Map<Country>.WriteRecord() Instance = {0}", obj );
				map.BaseWriteRecord( obj, record );
				record.OnSet( "RegionId", () => { return obj.Region == null ? null : obj.Region.Id; } );
				DEBUG.Unindent();
			};
			map.LoadRecord = ( record, obj ) => {
				DEBUG.IndentLine( "\n-- Map<Country>.LoadRecord() Record = {0}", record );
				map.BaseLoadRecord( record, obj );
				record.OnGet( "RegionId", val => { obj.Region = val == null ? null : link.Find<Region>( x => x.Id == val ); } );
				DEBUG.Unindent();
			};
			map.OnRefresh = obj => {
				DEBUG.IndentLine( "\n-- Map<Country>.OnRefresh() Instance = {0}", obj );
				obj = map.BaseOnRefresh( obj );
				obj.Employees.Clear(); obj.Employees.AddRange( link.Query<Employee>().Where( x => x.CountryId == obj.Id ).ToList() );
				DEBUG.Unindent(); return obj;
			};

			map.OnInsert = obj => {
				DEBUG.IndentLine( "\n-- Map<Country>.OnInsert() Instance = {0} ...", obj );
				obj.Region = link.Sync( obj.Region, KMaps.SyncReason.Insert );
				obj = map.BaseOnInsert( obj );
				link.Sync<Employee>( obj.Employees, KMaps.SyncReason.Insert );
				DEBUG.Unindent(); return obj;
			};
			map.OnUpdate = obj => {
				DEBUG.IndentLine( "\n-- Map<Country>.OnUpdate() Instance = {0} ...", obj );
				obj.Region = link.Sync( obj.Region, KMaps.SyncReason.Update );
				obj = map.BaseOnUpdate( obj );
				link.Sync<Employee>( obj.Employees, KMaps.SyncReason.Update );
				DEBUG.Unindent(); return obj;
			};
			map.OnDelete = obj => {
				DEBUG.IndentLine( "\n-- Map<Country>.OnDelete() Instance = {0} ...", obj );
				link.Sync<Employee>( obj.Employees, KMaps.SyncReason.Delete );
				obj = map.BaseOnDelete( obj );
				DEBUG.Unindent(); return obj;
			};

			map.Validate(); return map;
		}