public static IQueryable <TEntity> EagerFetchAll <TEntity>(this IQueryable <TEntity> query) { // hack the session reference out of the provider - or is // there a better way to do this? //IStatelessSession session = (IStatelessSession)query.Provider.GetType().GetProperty("Session").GetValue(query.Provider); //ISession session = (ISession)query.Provider.GetType() // .GetProperty("Session", System.Reflection.BindingFlags.Instance // | System.Reflection.BindingFlags.NonPublic) // .GetValue(query.Provider); var entityType = typeof(TEntity); var sessionFactory = Ioc.Create <ISessionFactory>(); IClassMetadata metaData = sessionFactory.GetClassMetadata(entityType); for (int i = 0; i < metaData.PropertyNames.Length; i++) { global::NHibernate.Type.IType propType = metaData.PropertyTypes[i]; // get eagerly mapped associations to other entities if (propType.IsAssociationType && !metaData.PropertyLaziness[i]) { ParameterExpression par = Expression.Parameter(entityType, "p"); Expression propExp = Expression.Property(par, metaData.PropertyNames[i]); Type relatedType = null; LambdaExpression lambdaExp; string methodName; if (propType.ReturnedClass.IsGenericCollection()) { relatedType = propType.ReturnedClass.GetGenericArguments()[0]; var funcType = typeof(Func <,>).MakeGenericType(entityType, typeof(IEnumerable <>).MakeGenericType(relatedType)); lambdaExp = Expression.Lambda(funcType, propExp, par); methodName = "FetchMany"; } else { relatedType = propType.ReturnedClass; lambdaExp = Expression.Lambda(propExp, par); methodName = "Fetch"; } var fetchManyMethodImpl = typeof(EagerFetchingExtensionMethods).GetMethod(methodName).MakeGenericMethod(entityType, relatedType); Expression callExpr = Expression.Call(null, fetchManyMethodImpl, // first parameter is the query, second is property access expression query.Expression, lambdaExp ); LambdaExpression expr = Expression.Lambda(callExpr, par); Type fetchGenericType = typeof(NhFetchRequest <,>).MakeGenericType(entityType, propType.ReturnedClass); query = (IQueryable <TEntity>)Activator.CreateInstance(fetchGenericType, query.Provider, callExpr); } } return(query); }
void IConfigurable.Configure(global::NHibernate.Type.IType type, IDictionary <string, string> parms, global::NHibernate.Dialect.Dialect d) { try { parameters = parms; } catch (Exception ex) { //throw new NotImplementedException(); throw ex; } }
public int Delete(string query, object value, global::NHibernate.Type.IType type) { throw new NotSupportedException(NOT_ALLOWED); }