我有一个只有一个字段 ( Value
) 和以下映射的实体:
Id(x => x.Value).Column("value").Length(150);
当我执行以下代码时
using (var tx = Database.BeginTransaction())
{
for (int i = 0; i < 10; i++)
{
var e = new Entity { Id = "Value" + i };
Database.Entities.Add(e);
}
tx.Commit();
}
NHibernate在每次调用SELECT
之前执行一个语句。INSERT
像这样的东西:
NHibernate: SELECT * FROM entity entity_ WHERE entity_.value=@p0; @p0 = 'Value0'
NHibernate: INSERT INTO entity ...
NHibernate: SELECT * FROM entity entity_ WHERE entity_.value=@p0; @p0 = 'Value1'
NHibernate: INSERT INTO entity ...
NHibernate: SELECT * FROM entity entity_ WHERE entity_.value=@p0; @p0 = 'Value2'
NHibernate: INSERT INTO entity ...
如果我启用批量模式(设置adonet.batch_size
),它首先执行所有SELECT
语句,然后是INSERT
批量模式的语句。
这是预期的行为吗?如果是这样,我应该怎么做才能避免这种情况?