我怎么能在NHibernate中解决这个错误:“无法插入/选择id进行批量删除”

时间:2017-02-13 11:27:33

标签: c# hibernate nhibernate fluent-nhibernate

我正在使用NHibernateSQL Server,我正在尝试删除表格的行但是我收到此错误:

could not insert/select ids for bulk delete[SQL: /* insert-select for MYOBJECTMAPPED ids */ insert into #MYOBJECTMAPPED SELECT databasein0_.ID as ID FROM MYTABLE databasein0_ inner join MYPARENTTABLE databasein0_1_ on databasein0_.ID=databasein0_1_.Id WHERE ID=?]

看一下我正在尝试删除一行,但NHibernate正在理解错误并尝试使用 SELECT < INSERT / strong>(?????)

我的删除查询如下:

delete MYOBJECTMAPPED e where e.Id = :Id

其他信息:

我正在使用NHibernate版本3.2.0.4000

我无法更改我的NHibernate版本的数据库架构。

我尝试删除的对象是来自另一个对象的Subclassmap,每个对象都有自己的表。父表只是用于控制ID

public class MYOBJECTMAPPEDMAP : SubclassMap<MYOBJECTMAPPED>
{
    public MYOBJECTMAPPEDMAP ()
    {
        Table("MYTABLE");

        KeyColumn("ID");

        Map(x => x.Foo).Length(1000).Nullable();
    }
}


public class MYPARENTOBJECTMAP: ClassMap<MYPARENTOBJECT>
{
    public MYPARENTOBJECTMAP()
    {
        Table("MYTABLEPARENT");

        Id(x => x.Id);
    }
}

我的表是:

CREATE TABLE MYTABLE (
    [ID] [bigint] NOT NULL,
    [FOO] [varchar](1000) NULL
)

CREATE TABLE MYPARENTTABLE (
    [ID] [bigint] IDENTITY(1,1) NOT NULL,
    [NAME] [varchar](50) NOT NULL,
 CONSTRAINT [PK_MYPARENTTABLE] PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

0 个答案:

没有答案