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

时间:2012-10-31 13:51:39

标签: nhibernate

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

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

任何想法导致了什么?

班级:

    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]

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

[选择multisitep0_.PublicBookingID如PublicBo1_18_,multisitep0_.MultisiteID如Multisit2_18_,multisitep0_.NumAttendees如NumAtten3_18_,multisitep0_.AttendeeName如Attendee4_18_,multisitep0_.AttendeePhone如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为CallSpeed18_,multisitep0_.StartDate为StartDate18_,multisitep0_.StartTime为StartTime18_,multisitep0_ .Catering为Catering18_,multisitep0_。设备为Equipment18_ ,multisitep0_ .Telepresence为Telepre17_18_,multisitep0_.telepresenceConfigOption为telepre18_18_,multisitep0_.Sync为Sync18_,multisitep0_.ReceiveOrDial为Receive20_18_,multisitep0_.NoteTXT为NoteTXT18_ from tblMultisitePublicBooking multisitep0_ where multisitep0_.MultisiteID = 101156] [SQL:选择multisitep0_.PublicBookingID如PublicBo1_18_,multisitep0_.MultisiteID如Multisit2_18_,multisitep0_.NumAttendees如NumAtten3_18_,multisitep0_.AttendeeName如Attendee4_18_,multisitep0_.AttendeePhone如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为CallSpeed18_,multisitep0_.StartDate为StartDate18_,multisitep0_.StartTime为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_ from 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'."}

screen shot of error message

2 个答案:

答案 0 :(得分:2)

从TimeSpan到SQL'time'数据类型的映射似乎存在一些问题。

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

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

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

答案 1 :(得分:0)

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

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; }
}