2
Problem
I have an appointment with Linq Nhibernate in which subquery
I need to concatenate the results with a separator to compare it with the query
is similar to the following:
IQueryable<string> queryList = (from t1 in Session.Query<Table1>()
where (from t2 in Session.Query<Table2>()
where t2.Table1 == t1
select t2.Table1.Id + "#").Contains(t1.Id + "#")
select t1.Nome);
// É possivel de alguma forma informar o NHibernate para não parametrizar o "#"? Já que no Firebird esse modo está me trazendo problemas.
IEnumerable<string> list = queryList.ToList();
That would result in a query similar to this in SQL:
select T1.ID, T1.NOME
from TABLE1 T1
where (T1.ID || @ P0) in (select (T2.TABLE1_ID || @P1)
from TABLE2 T2
where T2.TABLE1_ID = T1.ID)
This query executed in a Firebird database, generates the following error: Dynamic SQL Error.
This problem of concatenating parameters in the Firebird select, I’m already trying to deal with here.
Question
Then I wonder if there is some way to configure Nhibernate so that in this query it does not parameterize the parameters but concatenate them in the query (In the mode SQL Injection == ON, hehe), SQL being similar to this:
select T1.ID, T1.NOME
from TABLE1 T1
where (T1.ID || '#') in (select (T2.TABLE1_ID || '#')
from TABLE2 T2
where T2.TABLE1_ID = T1.ID)
Is there any way to set this up in Nhibernate?
I implemented here and at first it worked as expected (There were some syntax errors and names in your code, but I believe it is because as you mentioned can not test, so I was correcting as necessary and edited your answer, follow the edition and revise to see if I did not screw up, hehe). I didn’t know (and had never thought about) this possibility, and this opens up other possibilities for new custom features in Nhibernate. Thank you for the reply.
– Fernando Leal
Show @Fernando... I apologize for the code - I am a fan of VB.NET, and I mixed information from the example I mentioned with other codes I had here: dirt in certain. Thank you for your editions.
– Jônatas Hudler