Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After some investigation I think I have a recipe: simply follow closely <code>NHibernate.Linq</code> implementation in order to have your own implementation and avoid an explicit NHibernate.Linq dependency in your client code. You just need to reproduce very closely <code>NHibernate.Linq.EagerFetchingExtensionMethods</code> class.</p> <p>It takes an interface: <code>IFetchRequest</code>, a class <code>FetchRequest</code> implementing <code>IFetchRequest</code> and a static class <code>EagerFetch</code> implementing extension methods. This is a sort of clone of <code>NHibernate.Linq.EagerFetchingExtensionMethods</code> class.</p> <p>Just define:</p> <pre><code>public interface IFetchRequest&lt;TQueried, TFetch&gt; : IOrderedQueryable&lt;TQueried&gt; {} </code></pre> <p>which mimics <code>NHibernate.Linq.INhFetchRequest&lt;TQueried, TFetch&gt;</code></p> <p>then define an implementation:</p> <pre><code>public class FetchRequest&lt;TQueried, TFetch&gt; : IFetchRequest&lt;TQueried, TFetch&gt; { #region IEnumerable&lt;TQueried&gt; Members public IEnumerator&lt;TQueried&gt; GetEnumerator(){ return NhFetchRequest.GetEnumerator(); } #endregion #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return NhFetchRequest.GetEnumerator(); } #endregion #region IQueryable Members public Type ElementType { get { return NhFetchRequest.ElementType; } } public System.Linq.Expressions.Expression Expression { get { return NhFetchRequest.Expression; } } public IQueryProvider Provider { get { return NhFetchRequest.Provider; } } #endregion public FetchRequest(INhFetchRequest&lt;TQueried, TFetch&gt; nhFetchRequest){ NhFetchRequest = nhFetchRequest; } public INhFetchRequest&lt;TQueried, TFetch&gt; NhFetchRequest { get; private set; } } </code></pre> <p>This one simply holds a nHibernate implementation and forwards every method to that member.</p> <p>Finally:</p> <pre><code>public static class EagerFetch { /* replacing methods from NHibernate.Linq.EagerFetchingExtensionMethods private static INhFetchRequest&lt;TOriginating, TRelated&gt; CreateFluentFetchRequest&lt;TOriginating, TRelated&gt;(MethodInfo currentFetchMethod, IQueryable&lt;TOriginating&gt; query, LambdaExpression relatedObjectSelector); public static INhFetchRequest&lt;TOriginating, TRelated&gt; Fetch&lt;TOriginating, TRelated&gt;(this IQueryable&lt;TOriginating&gt; query, Expression&lt;Func&lt;TOriginating, TRelated&gt;&gt; relatedObjectSelector); public static INhFetchRequest&lt;TOriginating, TRelated&gt; FetchMany&lt;TOriginating, TRelated&gt;(this IQueryable&lt;TOriginating&gt; query, Expression&lt;Func&lt;TOriginating, IEnumerable&lt;TRelated&gt;&gt;&gt; relatedObjectSelector); public static INhFetchRequest&lt;TQueried, TRelated&gt; ThenFetch&lt;TQueried, TFetch, TRelated&gt;(this INhFetchRequest&lt;TQueried, TFetch&gt; query, Expression&lt;Func&lt;TFetch, TRelated&gt;&gt; relatedObjectSelector); public static INhFetchRequest&lt;TQueried, TRelated&gt; ThenFetchMany&lt;TQueried, TFetch, TRelated&gt;(this INhFetchRequest&lt;TQueried, TFetch&gt; query, Expression&lt;Func&lt;TFetch, IEnumerable&lt;TRelated&gt;&gt;&gt; relatedObjectSelector); */ public static IFetchRequest&lt;TOriginating, TRelated&gt; Fetch&lt;TOriginating, TRelated&gt;(this IQueryable&lt;TOriginating&gt; query, Expression&lt;Func&lt;TOriginating, TRelated&gt;&gt; relatedObjectSelector){ var fetch = EagerFetchingExtensionMethods.Fetch(query, relatedObjectSelector); return new FetchRequest&lt;TOriginating, TRelated&gt;(fetch); } public static IFetchRequest&lt;TOriginating, TRelated&gt; FetchMany&lt;TOriginating, TRelated&gt;(this IQueryable&lt;TOriginating&gt; query, Expression&lt;Func&lt;TOriginating, IEnumerable&lt;TRelated&gt;&gt;&gt; relatedObjectSelector){ var fecth = EagerFetchingExtensionMethods.FetchMany(query, relatedObjectSelector); return new FetchRequest&lt;TOriginating, TRelated&gt;(fecth); } public static IFetchRequest&lt;TQueried, TRelated&gt; ThenFetch&lt;TQueried, TFetch, TRelated&gt;(this IFetchRequest&lt;TQueried, TFetch&gt; query, Expression&lt;Func&lt;TFetch, TRelated&gt;&gt; relatedObjectSelector){ var impl = query as FetchRequest&lt;TQueried, TFetch&gt;; var fetch = EagerFetchingExtensionMethods.ThenFetch(impl.NhFetchRequest, relatedObjectSelector); return new FetchRequest&lt;TQueried, TRelated&gt;(fetch); } public static IFetchRequest&lt;TQueried, TRelated&gt; ThenFetchMany&lt;TQueried, TFetch, TRelated&gt;(this IFetchRequest&lt;TQueried, TFetch&gt; query, Expression&lt;Func&lt;TFetch, IEnumerable&lt;TRelated&gt;&gt;&gt; relatedObjectSelector){ var impl = query as FetchRequest&lt;TQueried, TFetch&gt;; var fetch = EagerFetchingExtensionMethods.ThenFetchMany(impl.NhFetchRequest, relatedObjectSelector); return new FetchRequest&lt;TQueried, TRelated&gt;(fetch); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload