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
}