Linq to Nhibernate performance optimization (Entry level)

Source: Internet
Author: User

Recently are in the use of NHibernate and database dealing, to tell the truth, I think nhibernate is better than ADO, but in some complex query nhibernate is not as good as ADO. No more nonsense, let's talk about performance optimizations for LINQ to NHibernate.

1th: It should be clear whether the current code is executed on the database or in memory (or when it should be done on the database, when it should be done in memory)


When we do the query, the common use method

The IQueryable interface is used above, it will sift through the data before returning to us

This is in the database, directly the entire list is returned, because the ToList method is used.

So, when doing the query, what operations to put on the database level to do, what operations to put into memory to do, these are we have to consider. Usually these should pay attention to these details, such as a system to increase the annual data volume only 2000, with more than two years this system is scrapped, because the query speed will be more and more slowly with the volume of data, and we can do is to deal with these details well. As long as the sequence returns the IEnumerable words, this is the LINQ to object, it will take the database data, all to put in memory, in operation. So we can get the database to do more for us to do, as much as possible. Generally: in the final tolist.

2nd: Count and any to determine whether a sequence exists in the collection.

There is no problem with count>0 greater than zero to determine whether a sequence contains an element for an Array, list<t>, or collection<t>. But in some cases, there is a big problem. The any method is generic, so it is best to use this to judge.

This blog is just to share their humble opinion to everyone, if not, welcome to point out.

Linq to Nhibernate performance optimization (Entry level)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.