我有两个班级:
public class DepotType
{
public virtual Depot Depot {get;set;}
/*other properties*/
}
public class Depot
{
public virtual string Name {get;set;}
/*other properties*/
}
我做了以下odata查询:
http://localhost:63236/OData/DepotPlaces?$expand=Depot&$filter=Depot/Name eq 'asd'
但是,我收到以下错误:ORA-12704: character set mismatch
Nhibernate生成以下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)]
我尝试手动编写类似的LINQ
查询:
var test = _repository.Query().Where(d => d.Depot.Name == "asd").ToList();
生成的sql:
SELECT ...
FROM "DepotPlaces" depotplace0_
INNER JOIN "Depots" depot1_ ON depotplace0_."depotId"=depot1_."id"
WHERE depot1_."depotName"=:p0;
:p0 = 'asd' [Type: String (0)]
CAST
运算符的主要区别。我不知道为什么它存在于第一个sql
查询中。而且,如果我在SQL Developer
中运行此查询,则会收到相同的错误。如果我删除p0
参数并写入NULL
,则脚本可以正常工作。
答案 0 :(得分:0)
找到了答案。我必须添加以下选项:
[EnableQuery(HandleNullPropagation = HandleNullPropagationOption.False)]