Пример #1
0
		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;
		}
Пример #2
0
		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;
		}
Пример #3
0
		public static void Test_Query( IKLink link)
		{
			Console.WriteLine( "\n===== Querying some regions..." ); Console.ReadLine();
			var cmd = link.Query<Region>().Where( x => x.Id >= "3" );
			foreach( var obj in cmd ) Console.WriteLine( "\n>> Region: {0}", obj );
		}