コード例 #1
0
 public virtual SystemProcess UpdateSystemProcess(SystemProcess entity)
 {
     if (entity.IsTransient()) return entity;
     SystemProcess other = GetSystemProcess(entity.SystemProcessId);
     if (entity.Equals(other)) return entity;
     string sql=@"Update SystemProcess set  [Name]=@Name
                     , [Description]=@Description
                     , [Enabled]=@Enabled
                     , [DisplayOrder]=@DisplayOrder
                     , [Ip]=@Ip
                     , [Port]=@Port
                      where SystemProcessID=@SystemProcessID";
     SqlParameter[] parameterArray=new SqlParameter[]{
              new SqlParameter("@Name",entity.Name)
             , new SqlParameter("@Description",entity.Description ?? (object)DBNull.Value)
             , new SqlParameter("@Enabled",entity.Enabled)
             , new SqlParameter("@DisplayOrder",entity.DisplayOrder)
             , new SqlParameter("@Ip",entity.Ip ?? (object)DBNull.Value)
             , new SqlParameter("@Port",entity.Port ?? (object)DBNull.Value)
             , new SqlParameter("@SystemProcessID",entity.SystemProcessId)};
     SqlHelper.ExecuteNonQuery(this.ConnectionString,CommandType.Text,sql,parameterArray);
     return GetSystemProcess(entity.SystemProcessId);
 }
コード例 #2
0
 public virtual SystemProcess InsertSystemProcess(SystemProcess entity)
 {
     SystemProcess other=new SystemProcess();
     other = entity;
     if(entity.IsTransient())
     {
         string sql=@"Insert into SystemProcess ( [Name]
         ,[Description]
         ,[Enabled]
         ,[DisplayOrder]
         ,[Ip]
         ,[Port] )
         Values
         ( @Name
         , @Description
         , @Enabled
         , @DisplayOrder
         , @Ip
         , @Port );
         Select scope_identity()";
         SqlParameter[] parameterArray=new SqlParameter[]{
              new SqlParameter("@Name",entity.Name)
             , new SqlParameter("@Description",entity.Description ?? (object)DBNull.Value)
             , new SqlParameter("@Enabled",entity.Enabled)
             , new SqlParameter("@DisplayOrder",entity.DisplayOrder)
             , new SqlParameter("@Ip",entity.Ip ?? (object)DBNull.Value)
             , new SqlParameter("@Port",entity.Port ?? (object)DBNull.Value)};
         var identity=SqlHelper.ExecuteScalar(this.ConnectionString,CommandType.Text,sql,parameterArray);
         if(identity==DBNull.Value) throw new DataException("Identity column was null as a result of the insert operation.");
         return GetSystemProcess(Convert.ToInt32(identity));
     }
     return entity;
 }