Go to the documentation of this file.00001 using System.Linq;
00002 using N2.Engine;
00003 using N2.Persistence.NH;
00004 using N2.Details;
00005 using NHibernate.Linq;
00006 using N2.Persistence.Finder;
00007
00008 namespace N2.Linq
00009 {
00010 public static class EngineExtensions
00011 {
00016 public static IQueryable<T> Query<T>(this IEngine engine)
00017 {
00018 var q = engine.Resolve<ISessionProvider>().OpenSession.Session.Query<T>();
00019 if(typeof(ContentItem).IsAssignableFrom(typeof(T)))
00020 return new ContentQueryable<T>(q);
00021 return q;
00022 }
00023
00028 public static IQueryable<T> QueryItems<T>(this IEngine engine) where T : ContentItem
00029 {
00030 return engine.QueryItems<T>(VersionOption.Exclude);
00031 }
00032
00038 public static IQueryable<T> QueryItems<T>(this IEngine engine, VersionOption versions) where T : ContentItem
00039 {
00040 var q = engine.Query<T>();
00041 if (versions == N2.Persistence.Finder.VersionOption.Exclude)
00042 q = q.Where(i => i.VersionOf == null);
00043 return q;
00044 }
00045
00049 public static IQueryable<ContentItem> QueryItems(this IEngine engine)
00050 {
00051 return engine.QueryItems<ContentItem>(VersionOption.Exclude);
00052 }
00053
00058 public static IQueryable<ContentItem> QueryItems(this IEngine engine, VersionOption versions)
00059 {
00060 return engine.QueryItems<ContentItem>(versions);
00061 }
00062
00067 public static IQueryable<T> QueryDetails<T>(this IEngine engine) where T : ContentDetail
00068 {
00069 return engine.Query<T>();
00070 }
00071
00075 public static IQueryable<DetailCollection> QueryDetailCollections(this IEngine engine)
00076 {
00077 return engine.Query<DetailCollection>();
00078 }
00079 }
00080 }