在uniqueidentifier上使用Join时出错 - 将uniqueidentifier转换为numeric

时间:2012-07-08 15:59:20

标签: nhibernate join sql-server-ce fluent

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

1 个答案:

答案 0 :(得分:1)

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

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

SQL Server尝试将左手值从uniqueidentifierGuid)转换为numeric,因为右手值为numeric值 - 数字减去操作且操作数较少

您的QueryOver表达式的protectionGroupIdentifier.GroupGuid部分中包含Where值。检查GroupGuid是否确实是Guid属性。如果它是object属性,请将其强制转换为Guid