Sql generated by Linq

Asked

Viewed 55 times

2

Hello, I would like to know how to see the sql code that a String expression generates to be executed by ADO.Net.

I am using Nhibernate as a ORM framework.

1 answer

1


Do a function like this

public string GetGeneratedSql(System.Linq.IQueryable queryable, ISession session)
{
    var sessionImp = (ISessionImplementor) session;
    var nhLinqExpression = new NhLinqExpression(queryable.Expression, sessionImp.Factory);
    var translatorFactory = new ASTQueryTranslatorFactory();
    var translators = translatorFactory.CreateQueryTranslators(nhLinqExpression, null, false, sessionImp.EnabledFilters, sessionImp.Factory);

    return translators[0].SQLString;
}

Source

Browser other questions tagged

You are not signed in. Login or sign up in order to post.