0

我在 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 类型

4

1 回答 1

1

看起来您的GroupGuid值未正确转换为 SQL。它应该在值周围加上单引号。

pg.ProtectionGroupIndentifierGroupGuidId = '11111111-1111-1111-1111-111111111111'

SQL Server 尝试将左侧值从uniqueidentifier( Guid) 转换为numeric,因为右侧值是numeric具有少量操作数的数值减法运算。

You have protectionGroupIdentifier.GroupGuid value in Where part of your QueryOver expression. Check if GroupGuid is indeed Guid property. If it's an object property, cast it to Guid.

于 2012-07-08T17:22:21.107 回答