批量更新从更新返回意外行数 - 更新行数?

时间:2012-10-29 13:12:20

标签: c# sql fluent-nhibernate

在删除一个表后立即在表中添加新行时,我遇到了这样的错误: “批量更新从更新返回意外行数;实际行数:%x;预期:%(x + 1)”,其中x - 是删除后和插入前的行数。

删除代码:

using (var session = factory.OpenSession())
{
    using (var transaction = session.BeginTransaction())
    {
        foreach (var row in rows)
        {
            session.Delete((Word)row.DataBoundItem);
        }
        transaction.Commit();
        session.Flush();
    }
}

添加代码:

using (var session = factory.OpenSession())
{
    using (var transaction = session.BeginTransaction())
    {
        language.AddWord(word);
        session.SaveOrUpdate(language);
        transaction.Commit();
        session.Flush();
    }
}

映射:

public WordMapping()
{
    Id(x => x.Id).GeneratedBy.Native();
    Map(x => x.Word1);
    Map(x => x.Word2);
        Map(x => x.Count);
        References(x => x.Language)
            .Not.LazyLoad();
}

SQL代码,写入debug:

NHibernate: INSERT INTO [Word] (Word1, Word2, Count, Language_id) 
    VALUES (@p0, @p1, @p2, @p3); 
    select SCOPE_IDENTITY();
    @p0 = 't2' [Type: String (4000)], 
    @p1 = 't2' [Type: String (4000)], 
    @p2 = 10 [Type: Int32 (0)], 
    @p3 = 1 [Type: Int32 (0)]
你可以给我一个暗示该怎么办?也许我应该以某种方式更新行数?

0 个答案:

没有答案