zoukankan      html  css  js  c++  java
  • 更新部分字段 NHibernate

    更新部分字段 NHibernate

      概述:

       在有些情况下,我只想更新记录中的一个字段的值.比如:浏览完这条记录后,我把其中的是否浏览置为1.

      Nhibernate中提供了Native SQL,其中有一个方法ExecuteUpdate()来实现这个功能.

      代码如下:   

    双击代码全选
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    public static bool UpdateIsBrowse(decimal id)
     
           {
     
               bool IsSuccess = false;
     
               ITransaction trans = session.BeginTransaction();
     
               try
     
               {
     
                   //2 修改记录
     
                   string sql = " update jkpt_oaxt_weatherforecast set Isbrowse=1 where Weatherforecastid=" + id;          
     
                   ISQLQuery Query = session.CreateSQLQuery(sql).AddEntity(typeof(JkptOaxtWeatherforecast));
     
                   Query.ExecuteUpdate();            
     
                   session.Flush();
     
                   trans.Commit();
     
                   //写日志
     
                   Helpers.SaveInfo("Update weatherforecast 's isbrowse Success!");
     
                   IsSuccess = true;
     
               }
     
               catch (Exception ex)
     
               {
     
                   IsSuccess = false;
     
                   trans.Rollback();
     
                   //写日志
     
                   Helpers.SaveInfo("更新是否浏览失败!错误提示如下:" + ex.Message);
     
               }
     
               finally
     
               {
     
                   if (session != null)
     
                   {
     
                       session.Clear();
     
                   }
     
               }
     
               return IsSuccess;
     
           }
  • 相关阅读:
    (转)MP4文件两种格式AVC1和H264的区别及利用FFMPEG demux为h264码流事项
    (转)【多媒体封装格式详解】--- AAC ADTS格式分析
    (转)使用FFMPEG类库分离出多媒体文件中的H.264码流
    (转)ffmpeg 从mp4上提取H264的nalu
    (原)hisi3531立体声pcm实现播放方式
    (转)关于yuv 格式:planar和semi-planar格式
    (转)LCD:LCD常用接口原理篇
    Instrumentation 两种方法 premain Agent
    解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variabl
    Java反射机制获取Class文件
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/3904008.html
Copyright © 2011-2022 走看看