Skip to content

Instantly share code, notes, and snippets.

@SlyNet
Created November 16, 2011 09:20
Show Gist options
  • Select an option

  • Save SlyNet/1369659 to your computer and use it in GitHub Desktop.

Select an option

Save SlyNet/1369659 to your computer and use it in GitHub Desktop.
mock fetch
public interface IFetchRequest<TQueried, TFetch> : IOrderedQueryable<TQueried> { }
public class FetchRequest<TQueried, TFetch> : IFetchRequest<TQueried, TFetch>
{
public IEnumerator<TQueried> GetEnumerator()
{
return NhFetchRequest.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return NhFetchRequest.GetEnumerator();
}
public Type ElementType
{
get { return NhFetchRequest.ElementType; }
}
public Expression Expression
{
get { return NhFetchRequest.Expression; }
}
public IQueryProvider Provider
{
get { return NhFetchRequest.Provider; }
}
public FetchRequest(INhFetchRequest<TQueried, TFetch> nhFetchRequest)
{
NhFetchRequest = nhFetchRequest;
}
public INhFetchRequest<TQueried, TFetch> NhFetchRequest { get; private set; }
}
public static class EagerFetch
{
public static IFetchRequest<TOriginating, TRelated> Fetch<TOriginating, TRelated>(this IQueryable<TOriginating> query, Expression<Func<TOriginating, TRelated>> relatedObjectSelector)
{
var fetch = EagerFetchingExtensionMethods.Fetch(query, relatedObjectSelector);
return new FetchRequest<TOriginating, TRelated>(fetch);
}
public static IFetchRequest<TOriginating, TRelated> FetchMany<TOriginating, TRelated>(this IQueryable<TOriginating> query, Expression<Func<TOriginating, IEnumerable<TRelated>>> relatedObjectSelector)
{
var fecth = EagerFetchingExtensionMethods.FetchMany(query, relatedObjectSelector);
return new FetchRequest<TOriginating, TRelated>(fecth);
}
public static IFetchRequest<TQueried, TRelated> ThenFetch<TQueried, TFetch, TRelated>(this IFetchRequest<TQueried, TFetch> query, Expression<Func<TFetch, TRelated>> relatedObjectSelector)
{
var impl = query as FetchRequest<TQueried, TFetch>;
var fetch = EagerFetchingExtensionMethods.ThenFetch(impl.NhFetchRequest, relatedObjectSelector);
return new FetchRequest<TQueried, TRelated>(fetch);
}
public static IFetchRequest<TQueried, TRelated> ThenFetchMany<TQueried, TFetch, TRelated>(this IFetchRequest<TQueried, TFetch> query, Expression<Func<TFetch, IEnumerable<TRelated>>> relatedObjectSelector)
{
var impl = query as FetchRequest<TQueried, TFetch>;
var fetch = EagerFetchingExtensionMethods.ThenFetchMany(impl.NhFetchRequest, relatedObjectSelector);
return new FetchRequest<TQueried, TRelated>(fetch);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment