/// <summary>
        /// Creates a new sysdiagrams record using async
        /// </summary>
        public static async Task<int> CreateAsync(sysdiagramsDO DO)
        {
            SqlParameter _name = new SqlParameter("name", SqlDbType.SysName);
            SqlParameter _principal_id = new SqlParameter("principal_id", SqlDbType.Int);
            SqlParameter _version = new SqlParameter("version", SqlDbType.Int);
            SqlParameter _definition = new SqlParameter("definition", SqlDbType.VarBinary);
            
            _name.Value = DO.name;
            _principal_id.Value = DO.principal_id;
            _version.Value = DO.version;
            _definition.Value = DO.definition;
            
            SqlParameter[] _params = new SqlParameter[] {
                _name,
                _principal_id,
                _version,
                _definition
            };

            string pid = ConfigurationManager.AppSettings["ePermitDAL"];

            return await DataCommon.ExecuteScalarAsync("[dbo].[sysdiagrams_Insert]", _params, pid);
            
        }
        /// <summary>
        /// Gets all sysdiagrams records
        /// </summary>
        public static async Task<sysdiagramsDO[]> GetAllAsync()
        {

            string pid = ConfigurationManager.AppSettings["ePermitDAL"];

            SafeReader sr = await DataCommon.ExecuteSafeReaderAsync("[dbo].[sysdiagrams_GetAll]", new SqlParameter[] { }, pid);
            
            List<sysdiagramsDO> objs = new List<sysdiagramsDO>();
            
            while(sr.Read()){

                sysdiagramsDO obj = new sysdiagramsDO();
                
                obj.name = sr.GetString(sr.GetOrdinal("name"));
                obj.principal_id = sr.GetInt32(sr.GetOrdinal("principal_id"));
                obj.diagram_id = sr.GetInt32(sr.GetOrdinal("diagram_id"));
                if (sr.IsDBNull(sr.GetOrdinal("version"))) { obj.version = null; } else { obj.version = sr.GetInt32(sr.GetOrdinal("version")); }
                if (sr.IsDBNull(sr.GetOrdinal("definition"))) { obj.definition = null; } else { obj.definition = sr.GetBytes(sr.GetOrdinal("definition")); }


                objs.Add(obj);
            }

            return objs.ToArray();
        }
        /// <summary>
        /// Selects sysdiagrams records by UK_principal_name
        /// </summary>
        public static async Task<sysdiagramsDO[]> GetByUK_principal_nameAsync(String name,
 Int32 principal_id)
        {

            SqlParameter _name = new SqlParameter("name", SqlDbType.SysName);
            SqlParameter _principal_id = new SqlParameter("principal_id", SqlDbType.Int);
			
            _name.Value = name;
            _principal_id.Value = principal_id;
			
            SqlParameter[] _params = new SqlParameter[] {
                _name,
                _principal_id
            };

            string pid = ConfigurationManager.AppSettings["ePermitDAL"];

            SafeReader sr = await DataCommon.ExecuteSafeReaderAsync("[dbo].[sysdiagrams_GetByUK_principal_name]", _params, pid);


            List<sysdiagramsDO> objs = new List<sysdiagramsDO>();
			
            while(sr.Read())
            {
                sysdiagramsDO obj = new sysdiagramsDO();
				
                obj.name = sr.GetString(sr.GetOrdinal("name"));
                obj.principal_id = sr.GetInt32(sr.GetOrdinal("principal_id"));
                obj.diagram_id = sr.GetInt32(sr.GetOrdinal("diagram_id"));
                if (sr.IsDBNull(sr.GetOrdinal("version"))) { obj.version = null; } else { obj.version = sr.GetInt32(sr.GetOrdinal("version")); }
                if (sr.IsDBNull(sr.GetOrdinal("definition"))) { obj.definition = null; } else { obj.definition = sr.GetBytes(sr.GetOrdinal("definition")); }

                objs.Add(obj);
            }

            return objs.ToArray();
        }
        /// <summary>
        /// Deletes a sysdiagrams record
        /// </summary>
        public static async Task<int> DeleteAsync(sysdiagramsDO DO)
        {
            SqlParameter _diagram_id = new SqlParameter("diagram_id", SqlDbType.Int);
            
            _diagram_id.Value = DO.diagram_id;
            
            SqlParameter[] _params = new SqlParameter[] {
                _diagram_id
            };

            string pid = ConfigurationManager.AppSettings["ePermitDAL"];

            return await DataCommon.ExecuteScalarAsync("[dbo].[sysdiagrams_Delete]", _params, pid);
        }