开发者

nhibernate optimisation

Hello I'm new with nhibernate, I'd like to fill a treeview with some information - a list of visit ("visites" in the code) for one customer - each visit contains a list of bill ("factures" in the code)

I wrote that code :

ISession session = NHibernate.DataAccess.Models.Repository.TSession();

var visites = (from v in session.Query<Visites>()
 where v.Clients.Idclient == lstClients.SelectedValue.ToString()
 && v.Supprime == false
 select v).ToList();

foreach (Visites v in visites)
{
 node = new TreeNode("Visite du " + v.Datevis.ToShortDateString());

 var liste = v.Factures.Where(f => !f.Masque).Where(f => !f.Recup);
 foreach (Factures f in liste)
 {
  node.Nodes.Add("Facture n°" + f.Nofacture.ToString());
 }
}

Please notice that :

  1. the list of the visit are filtered (the visit of one 开发者_运维技巧customer)
  2. the list of the bill are filtered (only the visible bill)

It works well but it is slow, for every visit there is a sql query. On my old code I made a sql query which retrieve all the visites on the customer left join the visible bill and with the good order I can fill the treeview.

What is the best practice for that query ?

regards


Add batch-size="n" to your mapping for the Visites.Factures collection, where n is the count of collections you want to load at once.

That means you'll only have a query for each n Visites instances.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜