0

使用 session.Delete 获取错误:“无法执行查询”。

当我复制查询并在 SQL Server Management Studio 中运行它时,选择查询运行没有问题。似乎问题出在删除或其他东西上……我使用相同的方法从其他表中删除了记录,并且似乎工作正常。

任何想法是什么原因造成的?

班上:

    public class MultisitePublicBooking
    {
        public virtual int Id { get; set; }
        public virtual int multisiteID { get; set; }
        public virtual DateTime startDate { get; set; }
        public virtual DateTime startTime { get; set; }
    }

    public MultisitePublicBookingMap()
    {
        Table("tblMultisitePublicBooking");

        Id(x => x.Id).Column("PublicBookingID");
        Map(x => x.multisiteID).Column("MultisiteID");
        Map(x => x.startDate).Column("StartDate");
        Map(x => x.startTime).Column("StartTime");

    }

表如下:

CREATE TABLE [dbo].[tblMultisitePublicBooking](
[PublicBookingID] [int] IDENTITY(1,1) NOT NULL,
[MultisiteID] [int] NULL,
[NumAttendees] [int] NULL,
[AttendeeName] [varchar](1024) NULL,
[AttendeePhone] [varchar](128) NULL,
[AtendeeEmail] [varchar](500) NULL,
[BookingPrice] [money] NULL,
[LID] [int] NULL,
[TimeZoneID] [int] NULL,
[DateTimeModified] [datetime] NULL,
[DateTimeCreated]  AS (getdate()),
[CurrentStep] [nvarchar](50) NULL,
[CallType] [nvarchar](8) NULL,
[CallSpeed] [nvarchar](10) NULL,
[StartDate] [date] NULL,
[StartTime] [time](7) NULL,
[endtime] [time](7) NULL,
[Duration] [time](7) NULL,
[Catering] [nvarchar](200) NULL,
[Equipment] [nvarchar](200) NULL,
[Telepresence] [bit] NULL,
[telepresenceConfigOption] [nvarchar](50) NULL,
[Sync] [bit] NULL,
[ReceiveOrDial] [varchar](50) NULL,
[NoteTXT] [text] NULL,
 CONSTRAINT [PK_tblMultisitePublicBooking] PRIMARY KEY CLUSTERED 
(
    [PublicBookingID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF,     ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

完整的错误信息是:无法执行查询

[ select multisitep0_.PublicBookingID as PublicBo1_18_, multisitep0_.MultisiteID as Multisit2_18_, multisitep0_.NumAttendees as NumAtten3_18_, multisitep0_.AttendeeName as Attendee4_18_, multisitep0_.AttendeePhone as Attendee5_18_, multisitep0_.AtendeeEmail as AtendeeE6_18_, multisitep0_.BookingPrice as BookingP7_18_, multisitep0_.LID as LID18_, multisitep0_.DateTimeModified as DateTime9_18_, multisitep0_.CurrentStep as Current10_18_, multisitep0_.CallType as CallType18_, multisitep0_.CallSpeed as CallSpeed18_, multisitep0_.StartDate as StartDate18_, multisitep0_.StartTime as StartTime18_, multisitep0_. Catering as Catering18_, multisitep0_psite_Equipment. Equipment. Telepresence 作为 Telepre17_18_,multisitep0_.telepresenceConfigOption 作为 telepre18_18_,multisitep0_.Sync 作为 Sync18_,multisitep0_.ReceiveOrDial 作为 Receive20_18_,multisitep0_.NoteTXT as NoteTXT18_ from tblMultisitePublicBooking multisitep0_ where multisitep0_.MultisiteID=101156 ] [SQL: select multisitep0_.PublicBookingID as PublicBo1_18_, multisitep0_.MultisiteID as Multisit2_18_, multisitep0_.NumAttendees as NumAtten3_18_, multisitep0_.AttendeeName as Attendee4_18_, multisitep0_.AttendeePhone as Attendee5_18_, multisitep0_ .AtendeeEmail 作为 AtendeeE6_18_,multisitep0_.BookingPrice 作为 BookingP7_18_,multisitep0_.LID 作为 LID18_,multisitep0_.DateTimeModified 作为 DateTime9_18_,multisitep0_.CurrentStep 作为 Current10_18_,multisitep0_.CallType 作为 CallType18_,multisitep0_.CallSpeed 作为 Call_Speed18_,multisitep0 Start_.StartD作为 StartTime18_,multisitep0_.Catering 作为 Catering18_,multisitep0_.Equipment 作为 Equipment18_,multisitep0_.Telepresence 作为 Telepre17_18_,multisitep0_。telepresenceConfigOption 作为 telepre18_18_, multisitep0_.Sync 作为 Sync18_, multisitep0_.ReceiveOrDial 作为 Receive20_18_, multisitep0_.NoteTXT 作为 NoteTXT18_ 来自 tblMultisitePublicBooking multisitep0_ where multisitep0_.MultisiteID=101156]

内部异常是:

{"Input string '20:00:00' was not in the correct format."}

    {"Unable to cast object of type 'System.TimeSpan' to type 'System.IConvertible'."}

错误信息的屏幕截图

4

2 回答 2

2

从 TimeSpan 到 SQL“时间”数据类型的映射似乎存在一些问题。

您可以通过像这样设置 startTime-property-mapping 来修复它:

        Map(x => x.startTime).CustomType("TimeAsTimeSpan");

正确设置映射后,您还可以删除指定的记录。

于 2012-11-01T14:30:36.627 回答
0

你是对的,问题出在sql server时间列映射中。你可以在这里阅读更多:这里

xml文件中的映射如下所示:

<property name="StartTime" type="TimeAsTimeSpan" />

实体将是:

public class MultisitePublicBooking
{
    public virtual int Id { get; set; }
    public virtual int MultisiteID { get; set; }
    public virtual DateTime StartDate { get; set; }
    public virtual TimeSpan StartTime { get; set; }
}
于 2012-10-31T16:21:52.270 回答