Ejemplo n.º 1
0
        /// <summary>
        /// Get the translated foreign key reference data.
        /// </summary>
        /// <param name="property">The current property information</param>
        /// <param name="foreignKeyValue">The foreign key value for the referenced data entity.</param>
        /// <param name="data">The data column foreign key reference attribute data.</param>
        /// <returns>The translated data entity object.</returns>
        private object SetForeginKeyReferenceData(PropertyInfo property, object foreignKeyValue, Nequeo.Data.Custom.DataColumnForeignKeyAttribute data)
        {
            // Get the get method of the property.
            MethodInfo method = property.GetGetMethod();

            string             tableName          = DataTypeConversion.GetSqlConversionDataType(dataContext.ProviderConnectionDataType, data.Name.TrimStart('_').Replace(".", "].["));
            string             colunmName         = DataTypeConversion.GetSqlConversionDataType(dataContext.ProviderConnectionDataType, data.ReferenceColumnName.TrimStart('_'));
            DataTypeConversion dataTypeConversion = new DataTypeConversion(dataContext.ProviderConnectionDataType);

            // Execute the queryable provider and return the constructed
            // sql statement and return the data.
            string    statement = dataTypeConversion.GetSqlStringValue(LinqTypes.GetDataType(data.ColumnType, dataContext.ProviderConnectionDataType), foreignKeyValue);
            DataTable table     = dataContext.ExecuteQuery("SELECT * FROM " + tableName + " WHERE " + colunmName + " = " + statement);

            // Get the anonymous type translator from datarow
            // to the foreign key reference property return type.
            Nequeo.Data.Control.AnonymousTypeFunction typeFunction = new Nequeo.Data.Control.AnonymousTypeFunction();
            return((table.Rows.Count > 0) ? typeFunction.TypeTranslator(table.Rows[0], method.ReturnType) : null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the list of sql parameters.
        /// </summary>
        /// <param name="functionParameters">The function parameters created.</param>
        /// <param name="functionValues">The function values created.</param>
        /// <param name="methodInfo">The current method information.</param>
        /// <param name="parameters">The parameter collection.</param>
        /// <returns>The list of parameters.</returns>
        public DbParameter[] GetParameters(ref string functionParameters, ref string functionValues,
                                           MethodInfo methodInfo, params Object[] parameters)
        {
            int    i             = -1;
            long   length        = -1;
            string dbType        = null;
            bool   isNullable    = true;
            string parameterName = null;

            System.Data.ParameterDirection parameterDirection = ParameterDirection.Input;

            // Create a new instance of the sql parameter collection.
            string functionParameterNames = string.Empty;
            string functionValueNames     = string.Empty;
            List <System.Data.SqlClient.SqlParameter> sqlParameters = new List <SqlParameter>();
            DataTypeConversion dataTypeConversion = new DataTypeConversion(ConnectionContext.ConnectionDataType.SqlDataType);

            // For each parameter within the method.
            foreach (ParameterInfo parameter in methodInfo.GetParameters())
            {
                // For each attribute for the parameter.
                foreach (object attribute in parameter.GetCustomAttributes(true))
                {
                    // If the attribute is the
                    // function parameter column attribute.
                    if (attribute is Nequeo.Data.Custom.FunctionParameterAttribute)
                    {
                        // Increment the parameter count.
                        i++;

                        // Cast the current attribute.
                        Nequeo.Data.Custom.FunctionParameterAttribute att =
                            (Nequeo.Data.Custom.FunctionParameterAttribute)attribute;

                        dbType             = att.DbType;
                        length             = att.Length;
                        parameterName      = att.Name;
                        isNullable         = att.IsNullable;
                        parameterDirection = att.ParameterDirection;

                        // Add each parameter to the collection.
                        sqlParameters.Add(new System.Data.SqlClient.SqlParameter(
                                              parameterName, Nequeo.Data.SqlServer.ClientDataType.GetSqlDbType(dbType), Convert.ToInt32(length),
                                              parameterDirection, isNullable, ((Byte)(0)), ((Byte)(0)), "", System.Data.DataRowVersion.Current, parameters[i]));

                        // If the parameter is an input type
                        // then add the parameter to the list.
                        if (parameterDirection == ParameterDirection.Input || parameterDirection == ParameterDirection.InputOutput)
                        {
                            functionParameterNames += parameterName + ", ";
                            functionValueNames     += dataTypeConversion.GetSqlStringValue(parameters[i].GetType(), parameters[i]) + ", ";
                        }
                    }
                }
            }


            // Get the parameters for the function and
            // add the last return value parameter.
            functionParameters = functionParameterNames.TrimEnd(' ', ',');
            functionValues     = functionValueNames.TrimEnd(' ', ',');
            sqlParameters.Add(new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", SqlDbType.Int, 4,
                                                                     ParameterDirection.ReturnValue, false, ((Byte)(0)), ((Byte)(0)), "", DataRowVersion.Current, null));

            // Return the sql parameters.
            return(sqlParameters.ToArray());
        }