C# · 12月 31, 2021

c# – List需要很长时间才能使用Nhibernate Criteria实例化

我有这个查询返回7行,在数据库中需要4ms,但要实例化1075ms.这只是时代的一个例子,它在物体上有所不同,但它似乎没有意义,它需要很长时间.任何关于如何提高速度的指针? var criteria = GetSession().CreatesqlQuery( @” select circt_id as CircuitId from normal_upstream where dni_equip_type = ‘A’ start with up_equip_stn_no in (:UpStationNo1) connect by prior equip_stn_no = up_equip_stn_no union select circt_id as CircuitId from normal_upstream where up_equip_stn_no in (:UpStationNo1)”) .AddScalar(“CircuitId”,NHibernateUtil.Int32).SetParameterList(“UpStationNo1”,upstreamStations) .List<int>()

SQL查询生成

select circt_id as CircuitId from normal_upstreamwhere dni_equip_type = ‘A’ start with up_equip_stn_no in ( ‘B’ /* :p0 */) connect by prior equip_stn_no = up_equip_stn_no union select circt_id as CircuitId from normal_upstream where up_equip_stn_no in ( ‘B’ /* :p1 */)

任何帮助是赞赏.谢谢

解决方法 显然,减缓的是SetParameterList调用.当我在8ms数据库和485ms实例化之前得到一些东西时,我格式化sql,这是可以接受的.我想要有一些更快的东西,但现在这样做.

这是我目前使用的代码:

var sql = String.Format( @”select circt_id as CircuitId from normal_upstream where dni_equip_type = ‘FDR_OCR’ start with up_equip_stn_no in ({0}) connect by prior equip_stn_no = up_equip_stn_no union select circt_id as CircuitId from normal_upstream where up_equip_stn_no in ({0})”,String.Join(“,”,upstreamStations.Select(x=>”‘”+x+”‘”).ToArray())); var criteria = GetSession().CreatesqlQuery(sql) .AddScalar(“CircuitId”,NHibernateUtil.Int32) .List(); return criteria;