Click here to Skip to main content
15,896,207 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 548.7K   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.Core
{
	using Kerosene.Tools;
	using System;
	using System.Collections.Generic;

	// ==================================================== 
	/// <summary>
	/// Represents the general characteristics of an arbitrary underlying database engine, and acts as a factory to
	/// create specific objects adapted to it.
	/// </summary>
	public partial interface IKEngine : ICloneable
	{
		/// <summary>
		/// Returns a new instance that is a copy of this original one.
		/// </summary>
		new IKEngine Clone();

		/// <summary>
		/// Returns a new instance that initially was a copy of this original one, but that then afterwards its
		/// properties are modified using values of the matching entries in the settings dictionary, if any is
		/// given.
		/// </summary>
		/// <param name="settings">An optional dictionary containing entries with the names of the properties whose
		/// new values are obtained from the matching entries. The non-matching ones are just ignored.</param>
		IKEngine Clone(Dictionary<string, object> settings);

		/// <summary>
		/// The case insensitive name for the underlying database engine this instance represents, typically being
		/// the data provider invariant name that supports that engine.
		/// </summary>
		string InvariantName { get; }

		/// <summary>
		/// If not null a string containing an agnostic server version specification for the underlying database
		/// engine this instance represents. This specification can be composed by an arbitrary number of numeric,
		/// alphanumeric, or mixed strings, separated by dots, including empty strings.
		/// </summary>
		string ServerVersion { get; }

		/// <summary>
		/// Gets whether the identifiers in the database, typically they being table and columns names, are case
		/// sensitive or not.
		/// </summary>
		bool CaseSensitive { get; }

		/// <summary>
		/// The standard prefix the underlying database engine uses for the name of the parameters of a command.
		/// </summary>
		string ParameterPrefix { get; }

		/// <summary>
		/// Whether the underlying database engine treats the command parameters as positional when encountered
		/// in a command string, or rather by name.
		/// </summary>
		bool PositionalParameters { get; }

		/// <summary>
		/// Whether the underlying database engine dialect provides a normalized syntax to implement the skip/take
		/// functionality or not.
		/// </summary>
		bool NormalizedSkipTake { get; }
	}

	// ==================================================== 
	public partial interface IKEngine
	{
		/// <summary>
		/// Factory method to create a collection of aliases instance adapted for the dialect of the underlying
		/// database engine.
		/// </summary>
		IKAliasCollection CreateAliasCollection();

		/// <summary>
		/// Factory method to create a collection of parameters instance adapted for the dialect of the underlying
		/// database engine.
		/// </summary>
		IKParameterCollection CreateParameterCollection();

		/// <summary>
		/// Factory method to create a parser instance adapted for the dialect of the underlying database engine.
		/// </summary>
		IKParser CreateParser();

		/// <summary>
		/// Creates a new raw command.
		/// </summary>
		/// <param name="link">The link the new command will be associated with.</param>
		IKCommandRaw CreateCommandRaw(IKLink link);

		/// <summary>
		/// Creates a new query command.
		/// </summary>
		/// <param name="link">The link the new command will be associated with.</param>
		IKCommandQuery CreateCommandQuery(IKLink link);

		/// <summary>
		/// Creates a new insert command.
		/// </summary>
		/// <param name="link">The link the new command will be associated with.</param>
		/// <param name="table">A dynamic lambda expression resolving into the name of the table.</param>
		IKCommandInsert CreateCommandInsert(IKLink link, Func<dynamic, object> table);

		/// <summary>
		/// Creates a new delete command.
		/// </summary>
		/// <param name="link">The link the new command will be associated with.</param>
		/// <param name="table">A dynamic lambda expression resolving into the name of the table.</param>
		IKCommandDelete CreateCommandDelete(IKLink link, Func<dynamic, object> table);

		/// <summary>
		/// Creates a new update command.
		/// </summary>
		/// <param name="link">The link the new command will be associated with.</param>
		/// <param name="table">A dynamic lambda expression resolving into the name of the table.</param>
		IKCommandUpdate CreateCommandUpdate(IKLink link, Func<dynamic, object> table);
	}
}
// ======================================================== 

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