private static IQueryTranslator[] CreateTranslators(string expressionStr, IQueryExpression queryExpression, string collectionRole, bool shallow, IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) { IQueryTranslatorFactory2 qtFactory = new ASTQueryTranslatorFactory(); return qtFactory.CreateQueryTranslators(expressionStr, queryExpression, collectionRole, shallow, enabledFilters, factory); }
public String ToSql(System.Linq.IQueryable queryable) { var sessionProperty = typeof(DefaultQueryProvider).GetProperty("Session", BindingFlags.NonPublic | BindingFlags.Instance); var session = sessionProperty.GetValue(queryable.Provider, null) as ISession; var sessionImpl = session.GetSessionImplementation(); var factory = sessionImpl.Factory; var nhLinqExpression = new NhLinqExpression(queryable.Expression, factory); var translatorFactory = new ASTQueryTranslatorFactory(); var translator = translatorFactory.CreateQueryTranslators(nhLinqExpression, null, false, sessionImpl.EnabledFilters, factory).First(); //in case you want the parameters as well //var parameters = nhLinqExpression.ParameterValuesByName.ToDictionary(x => x.Key, x => x.Value.Item1); return translator.SQLString; }