Beispiel #1
0
        /// <summary>
        /// Convert SQL server datatype to DataType instance
        /// </summary>
        /// <param name="sqlType">SQL Server datatype</param>
        /// <returns>DataType instance</returns>
        public static DataType FromSQLDataType(string sqlType, int?length, int?precision, int?scale)
        {
            SqlDbType result;

            if (!SqlDbType.TryParse(sqlType, true, out result))
            {
                throw new DataTypeConversionException($"Could not convert from '{sqlType}' to a valid datatype.");
            }

            return(new DataType(_sqlToOleDbMap[result], length, precision, scale));
        }
        public List <BaseEntity> GetListEntityByProcedureNameWithParam(string entityName, string procedureName, List <DefinitionStoreProce> listDefinition)
        {
            LogTo.Info("RUN STORE ENTITY = {0} IS STORE NAME = {1}", entityName, procedureName);
            using (var con = EntityManager.Instance.GetConnection(entityName))
                using (var sqlCommand = new SqlCommand())
                {
                    try
                    {
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = procedureName;
                        sqlCommand.Connection  = con;

                        if (listDefinition != null && listDefinition.Count > 0)
                        {
                            foreach (var definitionStoreProce in listDefinition)
                            {
                                ParameterDirection parameterDirection;
                                ParameterDirection.TryParse(definitionStoreProce.ParameterDirection, out parameterDirection);
                                SqlDbType oracleDbType;
                                SqlDbType.TryParse(definitionStoreProce.OracleDbType, out oracleDbType);
                                sqlCommand.Parameters.Add(new SqlParameter(definitionStoreProce.FieldName, oracleDbType, definitionStoreProce.Length, parameterDirection, false, 0, 0, "", DataRowVersion.Proposed, definitionStoreProce.FieldValue));
                            }
                        }
                        using (var dataReader = sqlCommand.ExecuteReader())
                        {
                            //Tang so luong doc ban ghi len 100 lan
                            var entity = EntityManager.Instance.GetMyEntity(entityName);
                            return(entity.PopulateBusinessObjectFromReader(dataReader));
                        }
                    }
                    catch (Exception ex)
                    {
                        LogTo.Error("Loi khi lay du lieu EntityName is {0} and ProcedureName is {1}",
                                    entityName, procedureName);
                        LogTo.Error("SQL ERROR:" + sqlCommand.CommandText);
                        throw new Exception("GetListEntitySql::Getall::Error occured.", ex);
                    }
                }
        }