Click here to Skip to main content
15,891,529 members
Articles / Hosted Services / Azure

Kerosene ORM: a dynamic, configuration-less and self-adaptive ORM for POCO objects supporting a SQL-like syntax from C#

Rate me:
Please Sign up or sign in to vote.
4.96/5 (71 votes)
1 Mar 2015CPOL35 min read 545.6K   4.6K   212  
The seventh version of the dynamic, configuration-less and self-adaptive Kerosene ORM library, that provides full real support for POCO objects, natural SQL-like syntax from C#, and advanced capabilities while being extremely easy to use.
// ======================================================== 
namespace Kerosene.ORM.WCF.Test.Client
{
	using Kerosene.ORM.Core;
	using Kerosene.ORM.SqlServer.v2008.Concrete;
	using Kerosene.ORM.SqlServer.v2012.Concrete;
	using Kerosene.ORM.Test;
	using Kerosene.Tools;
	using System;

	// ==================================================== 
	class Program
	{
		static void Main(string[] args)
		{
			// Just in case...
			DebugHelper.Initialize();

			ConsoleHelper.Header(true, "\n\n=== Press [Enter] to start WCF client ... ");

			// Registering the engines our app will use...
			KEngineFactory.Register(new KEngineSqlServer2008());
			KEngineFactory.Register(new KEngineSqlServer2012());

			// Initializing the types to use for WCF serialization...
			KTypesWCF.Initialize();
			KTypesWCF.RegisterType(typeof(CalendarDate));
			KTypesWCF.RegisterType(typeof(ClockTime));

			// Creating a connection package the server can use to adapt the link created for this client...
			dynamic package = new DeepObject();
			package.UserName = "My User Name";
			package.Password = "My Password";
			package.WhenDate = CalendarDate.Now;
			package.WhenTime = ClockTime.Now;
			Console.WriteLine("\n> Package = {0}", package);

			// Locating an engine that represents the underlying database type at the server...
			var provider = "SqlClient";
			var version = "11";
			var engine = KEngineFactory.Locate(provider, version);

			// Use the endpoint on you App.config file
			var endpoint = "Service_OnTcp_Endpoint";

			// Creating the link and connecting it automatically...
			var link = new KLinkWCF(engine, endpoint, package);

			// Do not forget to register the allowed transformers...
			link.AddTransformer<CalendarDate>(x => x.ToDateTime());
			link.AddTransformer<ClockTime>(x => x.ToString());

			Console.WriteLine("\n> Link = {0}", link);

			// Comment out the tests you want to execute...
			bool pressEnter = true;

			//Test_DynamicRecords.Raw_Query(link, pressEnter);
			//Test_DynamicRecords.Raw_Query_Multiple_Tables(link, pressEnter);
			//Test_DynamicRecords.Raw_Insert_JamesBond_Enumerate(link, pressEnter);
			//Test_DynamicRecords.Raw_Delete_JamesBond_Enumerate(link, pressEnter);
			//Test_DynamicRecords.Raw_Delete_JamesBond_No_Enumerate(link, pressEnter);
			//Test_DynamicRecords.Raw_Stored_Procedure(link, pressEnter);

			//Has no sense in a WCF context as the server side is a completely remote machine...
			//Test_DynamicRecords.With_Transaction_Scope(link, pressEnter);

			//Has no sense because in a WCF context the client has no notion of a direct/physical transaction...
			//Test_DynamicRecords.With_External_Transaction(link, pressEnter);

			//Test_DynamicRecords.With_Link_Transaction(link, pressEnter);

			//Test_DynamicRecords.Query_Basic(link, pressEnter);
			//Test_DynamicRecords.Query_Using_Dynamic_And_Indexed_Columns(link, pressEnter);
			//Test_DynamicRecords.Query_Using_Complex_Tags(link, pressEnter);
			//Test_DynamicRecords.Query_From_Multiple_Tables(link, pressEnter);
			//Test_DynamicRecords.Query_Using_In_Operator(link, pressEnter);
			//Test_DynamicRecords.Query_Using_NotIn_Operator(link, pressEnter);
			//Test_DynamicRecords.Query_With_Chained_Froms(link, pressEnter);
			//Test_DynamicRecords.Query_With_Several_Joins(link, pressEnter);
			//Test_DynamicRecords.Query_Select_Distinct(link, pressEnter);
			//Test_DynamicRecords.Query_With_Command_As_Source(link, pressEnter);
			//Test_DynamicRecords.Query_With_Simulated_SkipTake(link, pressEnter);
			//Test_DynamicRecords.Query_With_SkipTake(link, pressEnter);
			//Test_DynamicRecords.Query_Getting_One_Value(link, pressEnter);
			//Test_DynamicRecords.Query_With_Extended_Rounded_Syntax(link, pressEnter);
			//Test_DynamicRecords.Query_With_Extended_Square_Syntax(link, pressEnter);

			//Test_DynamicRecords.Insert_James_Bond_Enumerate(link, pressEnter);
			//Test_DynamicRecords.Delete_James_Bond_Enumerate(link, pressEnter);
			//Test_DynamicRecords.Delete_JamesBond_No_Enumerate(link, pressEnter);

			//Test_DynamicRecords.Update_Several_Rows(link, pressEnter);
			//Test_DynamicRecords.Delete_Manager_NotNull_Enumerate(link, pressEnter);
			//Test_DynamicRecords.Delete_Manager_NotNull_No_Enumerate(link, pressEnter);

			//Test_DynamicRecords.Query_With_Conversion_To_Anonymous(link, pressEnter);
			//Test_DynamicRecords.Query_With_Conversion_To_Type(link, pressEnter);
			//Test_DynamicRecords.Query_With_Complex_And_Recursive_Conversion(link, pressEnter);

			//Test_DynamicRecords.Nested_Updates_Avoiding_Foreign_Keys(link, pressEnter);
			//Test_DynamicRecords.Update_With_Row_Version(link, pressEnter);

			//Test_DynamicRecords.Query_Performance_Regions(link, pressEnter);

			// Remember to comment-out the following line if any of the map tests are also executed...
			Test_LazyMaps.Register_Maps(link, pressEnter, show: true);

			//Test_LazyMaps.Validate_Maps(link, pressEnter);
			//Test_LazyMaps.Clone_And_Dispose_Maps(link, pressEnter);

			//Test_LazyMaps.Region_Find_Root(link, pressEnter);
			//Test_LazyMaps.Region_List_All(link, pressEnter);
			//Test_LazyMaps.Region_Find_From_Cache(link, pressEnter);
			//Test_LazyMaps.Region_Find_Used_As_Query(link, pressEnter);
			//Test_LazyMaps.Region_Refresh_From_Cache(link, pressEnter);
			//Test_LazyMaps.Region_Refresh_Used_As_Query(link, pressEnter);

			//Test_LazyMaps.Region_Delete_Root_Isolated(link, pressEnter);
			//Test_LazyMaps.Region_Delete_Root(link, pressEnter);
			//Test_LazyMaps.Region_Delete_Arbitrary_Instance(link, pressEnter);

			//Test_LazyMaps.Region_Insert_Root_With_Childs(link, pressEnter);
			//Test_LazyMaps.Region_Insert_Child_With_Root(link, pressEnter);
			//Test_LazyMaps.Employee_Insert_Lateral(link, pressEnter);

			//Test_LazyMaps.Region_Update_Root(link, pressEnter);
			//Test_LazyMaps.Region_Update_Root_From_Child_Update(link, pressEnter);
			//Test_LazyMaps.Region_Insert_By_Update_Parent(link, pressEnter);

			Test_LazyMaps.Query_Performance_Regions(link, pressEnter);


			ConsoleHelper.Header(true, "\n\n=== Press [Enter] to finish client ... ");
			link.Dispose();

			ConsoleHelper.Header(true, "\n\n=== Press [Enter] to finish program ... ");
		}
	}
}
// ======================================================== 

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Spain Spain
mbarbac has worked in start-ups, multinational tech companies, and consulting ones, serving as CIO, CTO, SW Development Director, and Consulting Director, among many other roles.

Solving complex puzzles and getting out of them business value has ever been among his main interests - and that's why he has spent his latest 25 years trying to combine his degree in Theoretical Physics with his MBA... and he is still trying to figure out how all these things can fit together.

Even if flying a lot across many countries, along with the long working days that are customary in IT management and Consultancy, he can say that, after all, he lives in Spain (at least the weekends).

Comments and Discussions