Click here to Skip to main content
15,884,237 members
Articles / Web Development / ASP.NET

Signum Framework Principles

Rate me:
Please Sign up or sign in to vote.
4.74/5 (27 votes)
25 Jul 2011CPOL18 min read 98.8K   1.1K   86  
Explains the philosophy behind Signum Framework, an ORM with a full LINQ Provider that encourages an entities-first approach.
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Linq.Expressions;

namespace Signum.Utilities.ExpressionTrees
{
	/// <summary>
	/// Extension methods for IQueryable
	/// </summary>
	public static class QueryableExtensions
	{
		/// <summary>
		/// Returns wrapper that automatically expands expressions in LINQ queries
		/// </summary>
		public static IQueryable<T> ToExpandable<T>(this IQueryable<T> q)
		{
			return new ExpandableWrapper<T>(q);
		}
	}


	/// <summary>
	/// Wrapper for IQueryable that calls Expand
	/// </summary>
	internal class ExpandableWrapper<T> : IQueryable<T>, IQueryProvider
	{
		IQueryable<T> _item;

		public ExpandableWrapper(IQueryable<T> item)
		{
			_item = item;
		}

		public IQueryable CreateQuery(Expression expression)
		{
			return _item.Provider.CreateQuery(expression);
		}

		public object Execute(Expression expression)
		{
			return _item.Provider.Execute(expression.ExpandUntyped());
		}

		public IQueryable<S> CreateQuery<S>(Expression expression)
		{
			Expression res = expression.ExpandUntyped();
			return new ExpandableWrapper<S>(_item.Provider.CreateQuery<S>(res));
		}

		public S Execute<S>(Expression expression)
		{
			return _item.Provider.Execute<S>(expression);
		}

		IEnumerator<T> IEnumerable<T>.GetEnumerator()
		{
			return _item.GetEnumerator();
		}

		public Type ElementType
		{
			get { return _item.ElementType; }
		}

		public Expression Expression
		{
			get { return _item.Expression; }
		}

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return _item.GetEnumerator();
		}

		public IQueryProvider Provider
		{
			get { return this; }
		}
	}
}

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
Software Developer (Senior) Signum Software
Spain Spain
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.

www.signumframework.com

I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...

Comments and Discussions