【问题标题】:Error using Join on uniqueidentifier - convert uniqueidentifier to numeric在 uniqueidentifier 上使用 Join 时出错 - 将 uniqueidentifier 转换为数字
【发布时间】:2012-07-08 15:59:19
【问题描述】:

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

【问题讨论】:

    标签: nhibernate join sql-server-ce fluent


    【解决方案1】:

    您的 GroupGuid 值似乎未正确转换为 SQL。它的值应该有单引号。

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

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

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

    【讨论】:

    • GroupGuid 是 Guid 属性。但是当我使用 JoinQueryOver 时,NHibernate 不明白。当在 GroupGuid 实体 (ProtectionGroupCheckpointStorageObject) 上激活 QueryOver 时,Nhibernate 提供正确的 SQL,GroupGuid 类型为 Guid - [Type: Guid (0)]
    • 它看起来像 NHibernate 中的一个错误:在 2 个表之间使用 JoinQueryOver 时,NHibernate 无法将简单的 Guid 值转换为唯一标识符。需要你的建议。谢谢
    • ProtectionGroupIdentifier 是另一个实体、自定义类型还是组件?也许问题就出在这上面。
    • ProtectionGroupIdentifier 是一个组件。
    • 嗯,在Where中把两边都转换成字符串怎么样?或者只有一个并使用 Equals 而不是 ==。不确定它是否会起作用。如果你有一个常规的 Guid 属性而不是组件,也许这不会是一个问题......我有点没有想法,所以只是把任何东西放进去。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-25
    • 2010-11-26
    • 2018-04-06
    • 1970-01-01
    • 2015-01-03
    相关资源
    最近更新 更多