Update some fields in NHibernate

Source: Internet
Author: User

Overview:

In some cases, I just want to update the value of one field in the record. For example: After browsing this record, I set the browse to 1.

Native SQL is provided in NHibernate, with a method executeupdate () to implement this functionality.

The code is as follows:

public static bool Updateisbrowse (decimal id)
{
bool issuccess = false;

ITransaction trans = session. BeginTransaction ();
Try
{
//2 modified record
String sql = Update Jkpt_oaxt_we Atherforecast set isbrowse=1 where weatherforecastid= "+ ID;

Isqlquery Query = session. Createsqlquery (SQL). Addentity (typeof (Jkptoaxtweatherforecast));
Query.executeupdate ();
Session. Flush ();
Trans.commit ();
//write Log
Helpers.saveinfo ("Update weatherforecast ' s isbrowse success!");
Issuccess = true;                
}
catch (Exception ex)
{
Issuccess = false;
Trans. Rollback ();
//write Log
Helpers.saveinfo (update does not browse failed!) The error prompts are as follows: "+ ex." message);      
      
Finally
{
if (session!= null)
{
Session. Clear ();        
}
}
return issuccess
}

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.