我用流利的NHibernate的数据导入到SQL Server数据库。
我用自动映射在我的实体(这完美地工作)
Fluently.Configure(nhibernateConfig_)
.Mappings(map_ => map_.AutoMappings.Add(AutoMap
.AssemblyOf<EntityMapping>(new AutomapConfiguration())
.UseOverridesFromAssemblyOf<EntityMapping>()
.Conventions.AddFromAssemblyOf<EntityMapping>()));
并使用QueryOver从数据库中获取数据
public AttributeTranslation GetOrCreateAttributeTranslation(Attribute attribute_, string language_)
{
AttributeTranslation translation = _session
.QueryOver<AttributeTranslation>()
.And(trans_ => trans_.Attribute == attribute_)
.And(trans_ => trans_.Language == language_)
.SingleOrDefault();
if (translation == null) {
translation = new AttributeTranslation() {
Language = language_,
Attribute = attribute_
};
Save(translation);
}
return translation;
}
不幸的是,我处理我的输入,每个查询阅读和会话的进行每个提交的事务需要更长的时间和更长的时间。
// Surrounded in several for loops that process the input
using (ITransaction transaction = _repo.BeginTransaction()) {
Stopwatch transGetWatch = Stopwatch.StartNew();
AttributeTranslation translation = _repo.GetOrCreateAttributeTranslation(attribute, lang.Key);
transGetWatch.Stop();
translation.DisplayName = value;
_repo.Save(translation);
Stopwatch commitWatch = Stopwatch.StartNew();
transaction.Commit();
commitWatch.Stop();
Console.Write("\rGetTrans[{0}] Commit[{1}] ",
transGetWatch.ElapsedMilliseconds,
commitWatch.ElapsedMilliseconds);
}
我试图切换希洛的ID生成,但无济于事。
public class AttributeTranslationMapOverride : IAutoMappingOverride<AttributeTranslation>
{
public void Override(AutoMapping<AttributeTranslation> map_)
{
map_.Id(attr_ => attr_.Id).GeneratedBy.HiLo("attributeTranslationMaxLo");
}
}
查询并承诺以每待命3-4毫秒开始时和结束时某处大约80到100结束。
我不一定需要使整机性能下降,我只是希望它稳定在每次通话的最初3至4毫秒。
什么可能是怎么回事呢?