Click here to Skip to main content
15,886,110 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 542K   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.
// ======================================================== ScalarExecutor.cs
namespace Kerosene.ORM.Direct.Concrete
{
	using Kerosene.Tools;
	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.Linq;
	using System.Runtime.Serialization;
	using System.Text;

	// ==================================================== 
	/// <summary>
	/// Represents an object able to execute a scalar command, in a direct connection scenario,
	/// and to return the interger produced by that execution.
	/// </summary>
	public class ScalarExecutor : Core.Concrete.ScalarExecutor, IScalarExecutor
	{
		/// <summary>
		/// Initializes a new instance.
		/// </summary>
		/// <param name="cmd">The command this instance will be associated with.</param>
		public ScalarExecutor(Core.IScalarCommand cmd)
			: base(cmd)
		{
			var link = base.Link as IDataLink;
			if (link == null) throw new InvalidOperationException(
				"Link '{0}' of command '{1}' is not a direct link.".FormatWith(base.Link, cmd));
		}

		/// <summary>
		/// The link of the command this executor is associated with.
		/// </summary>
		public new IDataLink Link
		{
			get { return (IDataLink)base.Link; }
		}

		/// <summary>
		/// Invoked to execute the associated command and returns the integer produced by that
		/// execution.
		/// </summary>
		protected override int OnExecute()
		{
			if (IsDisposed) throw new ObjectDisposedException(this.ToString());
			if (Command.IsDisposed) throw new ObjectDisposedException(Command.ToString());
			if (Command.Link.IsDisposed) throw new ObjectDisposedException(Command.Link.ToString());

			var surrogate = new SurrogateDirect(Command);
			int result = surrogate.OnExecuteScalar();

			return result;
		}
	}
}
// ======================================================== 

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