Ejemplo n.º 1
0
        /// <summary>
        /// 向数据库中添加一条记录
        /// </summary>
        /// <param name="model">要添加的实体</param>
        /// <returns>插入数据的ID</returns>
        public int Insert(sysdiagrams model)
        {
            #region SQL语句
            const string sql = @"
INSERT INTO [dbo].[sysdiagrams] (
	[name]
	,[principal_id]
	,[version]
	,[definition]
)
VALUES (
	@name
	,@principal_id
	,@version
	,@definition
);select @@IDENTITY";
            #endregion
            var res = SqlHelper.ExecuteScalar(sql,
                                              new SqlParameter("@name", model.name),
                                              new SqlParameter("@principal_id", model.principal_id),
                                              new SqlParameter("@version", model.version),
                                              new SqlParameter("@definition", model.definition)
                                              );
            return(res == null ? 0 : Convert.ToInt32(res));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据主键ID更新一条记录
        /// </summary>
        /// <param name="model">更新后的实体</param>
        /// <returns>执行结果受影响行数</returns>
        public int Update(sysdiagrams model)
        {
            #region SQL语句
            const string sql = @"
UPDATE [dbo].[sysdiagrams]
SET 
	[name] = @name
	,[principal_id] = @principal_id
	,[version] = @version
	,[definition] = @definition
WHERE [name] = @name";
            #endregion
            return(SqlHelper.ExecuteNonQuery(sql,
                                             new SqlParameter("@name", model.name),
                                             new SqlParameter("@principal_id", model.principal_id),
                                             new SqlParameter("@diagram_id", model.diagram_id),
                                             new SqlParameter("@version", model.version),
                                             new SqlParameter("@definition", model.definition)
                                             ));
        }