I have two classes:
public class DepotType
{
public virtual Depot Depot {get;set;}
/*other properties*/
}
public class Depot
{
public virtual string Name {get;set;}
/*other properties*/
}
I made the following odata query:
http://localhost:63236/OData/DepotPlaces?$expand=Depot&$filter=Depot/Name eq 'asd'
but, I get the following error: ORA-12704: character set mismatch
Nhibernate generates the following sql:
SELECT ...
FROM "DepotPlaces" depotplace0_
LEFT OUTER JOIN "Depots" depot1_ ON depotplace0_."depotId"=depot1_."id"
WHERE
cast(CASE WHEN depotplace0_."depotId" IS NULL
THEN :p0
ELSE depot1_."depotName"
END AS VARCHAR2(255))=:p1
:p0 = NULL [Type: String (0)], :p1 = 'asd' [Type: String (0)]
I tried to write similar LINQ
query manually:
var test = _repository.Query().Where(d => d.Depot.Name == "asd").ToList();
The generated sql:
SELECT ...
FROM "DepotPlaces" depotplace0_
INNER JOIN "Depots" depot1_ ON depotplace0_."depotId"=depot1_."id"
WHERE depot1_."depotName"=:p0;
:p0 = 'asd' [Type: String (0)]
The main difference in the CAST
operator. I don't know why it exist in the first sql
query. And, if I run this query in the SQL Developer
I get the same error. If I delete the p0
parameter and write NULL
then script works correctly.
The answer is found. I have to add the following option:
[EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]