我将NHibernate 4与Fluent NHibernate一起使用,并将枚举属性存储在我的数据库中作为字符串(我理解为默认值)。
我发现当查询有嵌套的' where语句(即语句有多级括号,见下面的例子)。 NHibernate将枚举转换为整数,从而导致来自sql server的错误Conversion failed when converting the nvarchar value 'Registration' to data type int.
。
Linq查询示例:
var results =_session.Query<Entity>()
.Where(a =>
(a.WorkflowStatus == WorkflowStatusEnum.Registration
&& !a.SecurityGroup.Active
? WorkflowStatusEnum.Handover
: a.WorkflowStatus) == TenderWorkflowStatusEnum.Handover)
.Count();
以下SQL查询中的哪些结果:
SELECT CAST(COUNT(*) AS INT) AS col_0_0_
FROM [Asset] asset0_
LEFT OUTER JOIN [SecurityGroup] asset2_ ON asset0_.SecurityGroup_id = asset2_.Id
WHERE CAST(CASE WHEN asset0_.AssetLocationStatus = 0
AND NOT ( asset2_.Active = 1 ) THEN 'Canceled'
ELSE asset0_.AssetLocationStatus
END AS INT) = 0
除了重写Where子句以删除嵌套之外,还有什么我可以用来让NHibernate在创建语句时将枚举视为字符串吗?