误导 SQL 无法比较异常文本
Misleading SQL Exception Text cannot be compared
OrmLite 进行以下调用时出现异常:
return db.Select<T>(x => x.Name == name && x.PuId == puId).FirstOrDefault();
Exception :"System.Data.SqlClient.SqlException (0x80131904): The text,
ntext, and image data types cannot be compared or sorted, except when
usingIS NULL or LIKE operator.
名称是一个字符串,puid 是一个整数。该类型映射到 SQL Table,其中根本没有文本、NText 或图像类型的列。
当我查看 LastSQL 语句并从 SQL 服务器执行它时,它起作用了。当我用以下内容替换调用时,它也能正常工作
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 服务器有问题?我们仍在使用 2000 版本。我用了两种 SQLServer Dialect,但运气不好。
有人有想法吗?
这是 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
为了回答这个问题,这在最新版本的 SQL 服务器上运行没有问题。
可能会影响此行为的 OrmLite 的主要变化是从内联 SQL 参数中使用 Parameterized SQL Expressions 的变化。
您可以使用内联 SQL 参数使用 OrmLite's legacy APIs or by dropping down to use Custom SQL APIs。
OrmLite 进行以下调用时出现异常:
return db.Select<T>(x => x.Name == name && x.PuId == puId).FirstOrDefault();
Exception :"System.Data.SqlClient.SqlException (0x80131904): The text, ntext, and image data types cannot be compared or sorted, except when usingIS NULL or LIKE operator.
名称是一个字符串,puid 是一个整数。该类型映射到 SQL Table,其中根本没有文本、NText 或图像类型的列。
当我查看 LastSQL 语句并从 SQL 服务器执行它时,它起作用了。当我用以下内容替换调用时,它也能正常工作
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 服务器有问题?我们仍在使用 2000 版本。我用了两种 SQLServer Dialect,但运气不好。
有人有想法吗?
这是 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
为了回答这个问题,这在最新版本的 SQL 服务器上运行没有问题。
可能会影响此行为的 OrmLite 的主要变化是从内联 SQL 参数中使用 Parameterized SQL Expressions 的变化。
您可以使用内联 SQL 参数使用 OrmLite's legacy APIs or by dropping down to use Custom SQL APIs。