2016-09-29 12 views
2

我得到那個異常,當OrmLite進行下面的調用:誤導SQL異常文本不能比擬的

return db.Select<T>(x => x.Name == name && x.PuId == puId).FirstOrDefault(); 

例外:「System.Data.SqlClient.SqlException(0x80131904):文本, NTEXT,和圖像數據類型不能比較或排序,除非當 usingIS NULL或LIKE運算符。

名稱是字符串和PUID是一個Int。的類型被映射到具有類型的沒有列的SQL表文本,NText或ima ge。

當我查看LastSQLStatement並從SQL Server執行它時,它可以工作。當我用下面的調用替換,它工作正常,也

return db.SqlList<T>("SELECT Event_Id, Event_Num, Entry_On, Timestamp, Applied_Product, Source_Event, Event_Status, Confirmed, User_Id, Extended_Info, Comment_Id, PU_Id FROM Events WHERE ((Event_Num = @Event_Num) AND (PU_Id = @PU_Id))",new {Event_Num= "16J2730", PU_Id=91}).FirstOrDefault(); 

舊版本我服務的正常工作與相同的代碼。使用最新版本的servicestack和ormlite,我現在得到了這個奇怪的問題...

OrmLite的最新版本在舊版本的SQL Server中有問題嗎?我們仍然在2000版本。我用兩個SQLServer方言都沒有運氣。

任何人有想法?

這裏是Mythz要求

 public ProficyEvent TestGetByName(string name, int puId, bool withDetails = false) 
    { 
     using (IDbConnection db = OpenDBConnection()) 
     { 
      try 
      {     
       return db.Select<ProficyEvent>(x => x.Name == name && x.PuId == puId).FirstOrDefault();    
      } 
      catch (Exception ex) 
      { 
       log.ErrorFormat("Error querying database: {0}", ex.ToString()); 
       throw; 
      } 
     }   
    } 

[Alias("Events")] 
public class ProficyEvent:IProficyPuEntity 
{  
    [AutoIncrement] 
    [Alias("Event_Id")] 
    public int Id { get; set; }  
    [Ignore] 
    public string Code { get; set; } 
    [Ignore] 
    public string Desc { get; set; } 
    [Alias("Event_Num")] 
    public string Name { get; set; } 
    [Alias("Entry_On")] 
    public DateTime? LastModified { get; set; } 
    [Ignore] 
    public string LastModifiedBy { get; set; }  
    public DateTime? Timestamp { get; set; } 
    [Alias("Applied_Product")] 
    public int? AppliedProductId { get; set; } 
    [Ignore] 
    public string AppliedProductName { get; set; } 
    [Ignore] 
    public int OriginalProductId { get; set; } 
    [Ignore] 
    public string OriginalProductName { get; set; } 
    [Alias("Source_Event")] 
    public int? SourceEvent { get; set; } 
    [Alias("Event_Status")] 
    public int? EventStatus { get; set; } 
    [Ignore] 
    public string EventStatusName { get; set; } 
    public int Confirmed { get; set; } 
    [Alias("User_Id")] 
    public int UserId { get; set; } 
    [Alias("Extended_Info")] 
    public string ExtendedInfo { get; set; } 
    [Ignore] 
    public string Comment { get; set; } 
    [Alias("Comment_Id")] 
    public int? CommentId { get; set; }  
    [Ignore] 
    public IEnumerable<ProficyTest> TestResults { get; set; } 
    [Alias("PU_Id")] 
    public int PuId { get; set; } 
    [Ignore] 
    public string UnitName { get; set; } 
    [Ignore] 
    public string LineName { get; set; } 
} 

CREATE TABLE [dbo].[Events](
[Event_Id] [int] IDENTITY(1,1) NOT NULL, 
[Event_Num] [Varchar_Event_Number] NOT NULL, 
[PU_Id] [int] NOT NULL, 
[TimeStamp] [datetime] NOT NULL, 
[Applied_Product] [int] NULL, 
[Source_Event] [int] NULL, 
[Event_Status] [tinyint] NULL, 
[Confirmed] [bit] NOT NULL DEFAULT (0), 
[User_Id] [int] NULL, 
[Comment_Id] [int] NULL, 
[Entry_On] [datetime] NULL, 
[Testing_Status] [int] NULL DEFAULT (1), 
[Event_Subtype_Id] [int] NULL, 
[Start_Time] [Datetime_ComX] NULL, 
[Extended_Info] [varchar](255) NULL, 
[Converted_Timestamp] [datetime] NULL, 
[Orientation_X] [float] NULL, 
[Orientation_Y] [float] NULL, 
[Orientation_Z] [float] NULL, 
[Final_Dimension_Z] [real] NULL, 
[Final_Dimension_A] [real] NULL, 
[Initial_Dimension_A] [real] NULL, 
[Final_Dimension_X] [real] NULL, 
[Final_Dimension_Y] [real] NULL, 
[Initial_Dimension_Y] [real] NULL, 
[Initial_Dimension_Z] [real] NULL, 
[Initial_Dimension_X] [real] NULL, 
[Conformance] [tinyint] NULL, 
[Testing_Prct_Complete] [tinyint] NULL) 

CREATE TYPE [dbo].[Varchar_Event_Number] FROM [varchar](25) NOT NULL 
CREATE TYPE [dbo].[Datetime_ComX] FROM [datetime] NOT NULL 
+0

我們需要能夠重現問題以確定它是什麼,您可以提交現有表的CREATE TABLE語句,表的類定義以及您使用的存在問題的代碼(請使用真正的類型名稱而不是通用的'T'arg) – mythz

+0

對於使用最新版本的OrmLite,這個查詢運行沒有問題,也許這個異常是針對不同的查詢?否則,您可以嘗試使用最新版本的OrmLite。 – mythz

+0

謝謝Mythz。我使用最新版本。事實上,它在我沒有使用最新版本的情況下工作正常。您可以在SQL Server 2000 SP4上測試它嗎?在我的服務器上使用更高版本的SQL Server時,工作也很好(雖然不是同一個表和類)。它可能與舊版SQL Server不兼容嗎? – jbrabant

回答