In this section, we will be covering the batch size update. The batch size allows you to control the number of updates that go out in a single round trip to your database for the maintained databases.
Let’s have a look into a simple example in which we have set the batch size to 10 that will insert 10 records in a set.
Here is the complete implementation in which 25 records will be added to the database.
Currently let’s run your application and you see all those updates are hopping over to NHibernate profiler. We have 26 separate round trips to the database 25 for insertion and one retrieving the list of students.
Currently, why is that? The aim is because NHibernate needs to do a select scope identity as we are using the native identifier generation strategy in the mapping file for ID as shown in the following code.
So we need to use a altered method such as the guid.comb method. If we're going to go to guid.comb, we need to go over to our customer and change this to a guid. So that will work fine. Now let’s change from the native to guid.comb using the following code.
So it's the database that's answerable for making those IDs. The only way NHibernate can find out what ID was made was to select it directly afterwards. Besides, if we have created a batch of students, it will not be able match up the ID of the student that was created.
We must update our database. Let’s drop the student table and create a new table by specifying the following query, so go the SQL Server Object Explorer and right-click on the database and select the New Query… option.
It will open the query editor and and then specify the following query.
This question will first drop the current student table and then create a new table. As you can see that we have used UNIQUEIDENTIFIER rather than using an integer primary key as an ID.
Perform this query and then go to the Designer view and you will see that now the ID is created with a unique identifier as shown in the following image.
Now we need to remove the ID from the program.cs file, while inserting data, because now it will generate the guids for it automatically.
Currently run the application for a second time and have a look at the NHibernate profiler. Now the NHibernate profiler rather than creating 26 round trips will make only four.
It's implanted ten rows into the table, then additional ten rows, and later the lasting five. And after obligate, it has inserted one more for retrieving all the records.
NHibernate Related Interview Questions
|SQL Server 2008 Interview Questions||ASP.NET Interview Questions|
|LINQ Interview Questions||IBM Tivoli Interview Questions|
|Windows Presentation Foundation(WPF) Interview Questions||Windows Communication Foundation (WCF) Interview Questions|
|Ibm Tivoli Netcool Omnibus Interview Questions||Dynamic Link Library (DLL) Interview Questions|
|Advanced C# Interview Questions||Asp Dot Net Mvc 4 Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.