2012-07-08 10 views
0

我在sqlserverce上使用连贯NHibernate。 使用NHibernate QueryOver我尝试检索行 - NHibernate的自动生成氨基酸连接查询 ,我得到以下异常:在uniqueidentifier上使用连接时出错 - 将uniqueidentifier转换为数字

[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

看起来你GroupGuid VA的lue未正确转换为SQL。它应该有单引号的值。

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

的SQL Server试图从uniqueidentifierGuid)转换左手价值numeric,因为右手值是numeric值 - 几乎没有操作数数字减法运算。

您的protectionGroupIdentifier.GroupGuid值在您的QueryOver表达式的Where部分。检查GroupGuid的确属于Guid属性。如果它属于object属性,则将其投射到Guid

+0

GroupGuid是Guid Property。但是当我使用JoinQueryOver时,NHibernate不会计算它。当在GroupGuid实体(ProtectionGroupCheckpointStorageObject)上激活QueryOver时,Nhibernate提供正确的SQL和Guid类型的GroupGuid - [Type:Guid(0)] – Haimon 2012-07-08 19:16:05

+0

看起来像NHibernate中的一个错误:当在两个表之间使用JoinQueryOver时,NHibernate无法转换simple Guid价值uniqueidentifier。需要你的建议。谢谢 – Haimon 2012-07-09 09:08:41

+1

ProtectionGroupIdentifier是另一个实体还是自定义类型或组件?也许问题出在那。 – 2012-07-09 13:32:23

相关问题