代码之家  ›  专栏  ›  技术社区  ›  Sébastien Ollivier

当我对查询调用Update方法时,为什么NHibernate创建一个临时表?

  •  1
  • Sébastien Ollivier  · 技术社区  · 7 年前

    this.session.Query<EventEntity>()
         .Where(e => [...])
         .Update(c => new { Enabled = true });
    

    insert into HT_event SELECT evententit0_.Id as Id FROM event evententit0_ WHERE [...]
    UPDATE event SET Enabled=? WHERE (Id) IN (select Id from HT_event)
    

    为什么NHibernate创建一个临时表来存储id,而不是直接生成正确的IN子句?如何禁用此行为?

    为了提供更多信息,我使用了一个表每类的层次结构继承映射和按代码映射。我的 EventEntity 是一个抽象类:

    public abstract class EventEntity { ... }
    
    public class EventMap : ClassMapping<EventEntity> { ... }
    

    我还有一些其他实体继承自 事件实体

    public abstract class MatchEntity { ... }
    
    public class MatchMap : JoinedSubclassMapping<MatchEntity> { ... }
    

    谢谢你的帮助!

    1 回复  |  直到 7 年前
        1
  •  0
  •   Sébastien Ollivier    7 年前

    Hibernate提出了一种定制bulk id策略的方法,但目前NHibernate还不能使用它: https://github.com/nhibernate/nhibernate-core/issues/2004

    推荐文章