I have a query in LINQ and I need to capture the generated sql, but I did not succeed. The conversion to ObjectQuery that I found does not work. What is missing?
var sqlConsulta = (from a in Sessao.Query<RequisitorioNaoLevantado>()
where (a.Codvara == codigoVara) &&
(string.IsNullOrEmpty(numeroProcesso) ||
a.AcaoOriginaria.Equals(numeroProcesso))
select a);
var sqlGerado = (ObjectQuery)sqlConsulta;
var commandSql = sqlGerado.ToTraceString();
For sqlConsulta.ToString (), we have:
NHibernate.Linq.NhQueryable'1 [Template.Entities.Part.RequisitorNoUrePerformed]
The line (ObjectQuery) sqlQuery generates the exception:
"Cannont cast 'sqlConsulta' (which has an actual type of 'NHibernate.Linq.NhQueryable'1 [Template.Entities.Partner.NotReserved)' to 'System.Data.Objects.ObjectQuery"