我在sqlserverce上使用Fluent NHibernate。 使用NHibernate QueryOver我尝试检索一行 - NHibernate自动生成一个连接查询 我得到以下例外:
[SQL: SELECT tag FROM CheckpointToProtectionGroup cp2pg
JOIN CheckpointStorageObject cp ON cp.id = cp2pg.checkpoint_id
JOIN ProtectionGroupCheckpointStorageObject pg ON pg.id = cp2pg.vpg_id
WHERE cp.CheckpointIdentifierIdentifier = 1111 AND
pg.ProtectionGroupIdentifierGroupGuid =
11111111-1111-1111-1111-111111111111]
---> System.Data.SqlServerCe.SqlCeException:
The conversion is not supported.
[ Type to convert from (if known) = uniqueidentifier,
Type to convert to (if known) = numeric ]
从我看到的,似乎它试图将值--11111111-1111-1111-1111-111111111111转换为数字,但此值是Guid字段:
CheckpointToProtectionGroup checkpointToProtectionGroup = Session
.QueryOver<CheckpointToProtectionGroup>()
.JoinQueryOver( row => row.ProtectionGroup)
.Where(row => row.ProtectionGroupIdentifier.GroupGuid ==
protectionGroupIdentifier.GroupGuid)
.SingleOrDefault();
ProtectionGroupIdentifier.GroupGuid属于Guid类型
答案 0 :(得分:1)
看起来您的GroupGuid
值未正确转换为SQL。它应该在值周围有单引号。
pg.ProtectionGroupIndentifierGroupGuidId = '11111111-1111-1111-1111-111111111111'
SQL Server尝试将左手值从uniqueidentifier
(Guid
)转换为numeric
,因为右手值为numeric
值 - 数字减去操作且操作数较少
您的QueryOver表达式的protectionGroupIdentifier.GroupGuid
部分中包含Where
值。检查GroupGuid
是否确实是Guid
属性。如果它是object
属性,请将其强制转换为Guid
。