Esempio n. 1
0
        /// <summary>
        /// Translates an OleDb data table data to table data.
        /// </summary>
        /// <param name="dataTable">The datatable containing the data.</param>
        /// <returns>The translated data table</returns>
        public DataTable TranslateFunctionColumns(DataTable dataTable)
        {
            DataTable newTable = new DataTable("TableName");

            newTable.Columns.Add("ColumnName", typeof(String));
            newTable.Columns.Add("ColumnType", typeof(String));
            newTable.Columns.Add("ColumnNullable", typeof(Boolean));
            newTable.Columns.Add("ColumnOrder", typeof(Int32));
            newTable.Columns.Add("Length", typeof(Int64));
            newTable.Columns.Add("Precision", typeof(Int64));
            newTable.Columns.Add("IsOutParameter", typeof(Boolean));

            // For each row founs.
            foreach (DataRow row in dataTable.Rows)
            {
                // Create a new data row.
                DataRow rowNew = null;
                rowNew = newTable.NewRow();

                rowNew["ColumnName"]     = row["PARAMETER_NAME"];
                rowNew["ColumnType"]     = LinqToDataTypes.GetOleDbType(row["DATA_TYPE"].ToString());
                rowNew["ColumnNullable"] = row["IS_NULLABLE"];
                rowNew["ColumnOrder"]    = row["ORDINAL_POSITION"];
                rowNew["Length"]         = row["CHARACTER_MAXIMUM_LENGTH"];
                rowNew["Precision"]      = row["NUMERIC_PRECISION"];
                rowNew["IsOutParameter"] = (row["PARAMETER_TYPE"].ToString() == "4" ? true : false);

                // Add the current row to the table.
                newTable.Rows.Add(rowNew);
            }

            // Return the translated table.
            return(newTable);
        }
        /// <summary>
        /// Creates the foreign key columns.
        /// </summary>
        private void CreateForeignKeyColumns()
        {
            // Get all foreign key columns from the database.
            if (GetDatabaseForeignKeyColumns())
            {
                List <ForeignKey> array = new List <ForeignKey>();

                // For each column found in the table
                // iterate through the list and create
                // each field.
                foreach (var result in _tableFKs)
                {
                    // If the table item is not on the exclusion list.
                    if (_data.TableList.Contains(result.ForeignKeyTable.ToUpper(), new ToUpperComparer()) == !_tableListExclusion)
                    {
                        ForeignKey tableEntityForeignKey = new ForeignKey();
                        tableEntityForeignKey.ColumnName           = result.ColumnName;
                        tableEntityForeignKey.ColumnType           = result.ColumnType;
                        tableEntityForeignKey.Name                 = result.ForeignKeyTable;
                        tableEntityForeignKey.ForeignKeyTable      = result.ForeignKeyTable;
                        tableEntityForeignKey.IsNullable           = result.IsNullable;
                        tableEntityForeignKey.ForeignKeyColumnName = result.ForeignKeyColumnName;
                        tableEntityForeignKey.ForeignKeyOwner      = result.ForeignKeyOwner;

                        if (result.Precision != null && result.Precision > 0)
                        {
                            if ((result.Length <= result.Precision))
                            {
                                tableEntityForeignKey.Length = result.Length;
                            }
                            else
                            {
                                tableEntityForeignKey.Length = (long)result.Precision;
                            }
                        }
                        else
                        {
                            if (Common.LinqToDataTypes.GetLinqNullableType(result.ColumnType, Common.ConnectionProvider.GetConnectionDataType(_connectionDataType)))
                            {
                                tableEntityForeignKey.Length = result.Length;
                            }
                            else
                            {
                                tableEntityForeignKey.Length = LinqToDataTypes.DefaultLengthValue(ConnectionProvider.GetConnectionType(_connectionType));
                            }
                        }

                        // Assign the current reference.
                        array.Add(tableEntityForeignKey);
                    }
                }

                // Add all the foreign keys.
                _tableEntity.TableEntityForeignKey = array.ToArray();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Replaces the string if it is a number to a string with 'N' at the begining of the number.
        /// </summary>
        /// <param name="stringValue">The current string.</param>
        /// <returns>The newly formatted string.</returns>
        /// <exception cref="System.ArgumentNullException">Source object can not be null or empty</exception>
        public static String ReplaceNumbers(this String stringValue)
        {
            // If the string is null or empty.
            if (String.IsNullOrEmpty(stringValue))
            {
                throw new System.ArgumentNullException();
            }

            return((LinqToDataTypes.NumberValidator(stringValue)) ? "_" + stringValue + "_" : stringValue);
        }
Esempio n. 4
0
        /// <summary>
        /// Translates an OleDb data table data to table data.
        /// </summary>
        /// <param name="dataTable">The datatable containing the data.</param>
        /// <param name="dataTableEx">The datatable containing the table data.</param>
        /// <returns>The translated data table</returns>
        public DataTable TranslateTableReferenceKey(string tableName, string owner, DataTable dataTable, DataTable dataTableEx)
        {
            DataTable newTable = new DataTable("TableName");

            newTable.Columns.Add("TableName", typeof(String));
            newTable.Columns.Add("ColumnName", typeof(String));
            newTable.Columns.Add("ColumnType", typeof(String));
            newTable.Columns.Add("IsNullable", typeof(Boolean));
            newTable.Columns.Add("Length", typeof(Int64));
            newTable.Columns.Add("Precision", typeof(Int64));
            newTable.Columns.Add("ForeignKeyTable", typeof(String));
            newTable.Columns.Add("ForeignKeyColumnName", typeof(String));
            newTable.Columns.Add("ForeignKeyOwner", typeof(String));

            // For each row found.
            foreach (DataRow row in dataTable.Rows)
            {
                if (row["PK_TABLE_NAME"].ToString() == tableName)
                {
                    DataRow columNames = null;
                    try{
                        columNames = dataTableEx.Select("COLUMN_NAME = '" + row["FK_COLUMN_NAME"] + "'").First();
                    }
                    catch { }

                    if (columNames == null)
                    {
                        columNames = dataTableEx.Select("COLUMN_NAME = '" + row["PK_COLUMN_NAME"] + "'").First();
                    }

                    // Create a new data row.
                    DataRow rowNew = null;
                    rowNew = newTable.NewRow();

                    rowNew["TableName"]            = row["FK_TABLE_NAME"];
                    rowNew["ColumnName"]           = row["FK_COLUMN_NAME"];
                    rowNew["ColumnType"]           = LinqToDataTypes.GetOleDbType(columNames["DATA_TYPE"].ToString());
                    rowNew["IsNullable"]           = columNames["IS_NULLABLE"];
                    rowNew["Length"]               = columNames["CHARACTER_MAXIMUM_LENGTH"];
                    rowNew["Precision"]            = columNames["NUMERIC_PRECISION"];
                    rowNew["ForeignKeyTable"]      = row["PK_TABLE_NAME"].ToString();
                    rowNew["ForeignKeyColumnName"] = row["PK_COLUMN_NAME"];
                    rowNew["ForeignKeyOwner"]      = row["PK_TABLE_SCHEMA"];

                    // Add the current row to the table.
                    newTable.Rows.Add(rowNew);
                }
            }

            // Return the translated table.
            return(newTable);
        }
        /// <summary>
        /// Creates the data column.
        /// </summary>
        private void CreateDataColumns()
        {
            // Get all data columns from the database.
            if (GetDatabaseTableColumns())
            {
                // Get all primary keys.
                bool primaryKeysExist = GetDatabasePrimaryKeys();

                int          i     = 0;
                DataColumn[] array = new DataColumn[_columns.Count()];

                // For each column found in the table
                // iterate through the list and create
                // each field.
                foreach (var result in _columns)
                {
                    DataColumn tableEntityDataColumn = new DataColumn();
                    tableEntityDataColumn.IsAutoGenerated = result.IsComputed;
                    tableEntityDataColumn.Name            = result.ColumnName;

                    if (result.Precision != null && result.Precision > 0)
                    {
                        if ((result.Length <= result.Precision))
                        {
                            tableEntityDataColumn.Length = result.Length;
                        }
                        else
                        {
                            tableEntityDataColumn.Length = (long)result.Precision;
                        }
                    }
                    else
                    {
                        if (Common.LinqToDataTypes.GetLinqNullableType(result.ColumnType, Common.ConnectionProvider.GetConnectionDataType(_connectionDataType)))
                        {
                            tableEntityDataColumn.Length = result.Length;
                        }
                        else
                        {
                            tableEntityDataColumn.Length = LinqToDataTypes.DefaultLengthValue(ConnectionProvider.GetConnectionType(_connectionType));
                        }
                    }

                    tableEntityDataColumn.IsNullable   = result.ColumnNullable;
                    tableEntityDataColumn.DbType       = result.ColumnType;
                    tableEntityDataColumn.DbColumnName = result.ColumnName;

                    // If primary keys exist.
                    if (primaryKeysExist)
                    {
                        // If the current column is a primary key column.
                        if (_tablePKs.Where(k => k.PrimaryKeyName == result.ColumnName).Count() > 0)
                        {
                            tableEntityDataColumn.IsPrimaryKey = true;
                        }
                        else
                        {
                            tableEntityDataColumn.IsPrimaryKey = false;
                        }
                    }

                    // Is the primary key is seeded.
                    if (result.PrimaryKeySeed)
                    {
                        tableEntityDataColumn.IsSeeded = true;
                    }
                    else
                    {
                        tableEntityDataColumn.IsSeeded = false;
                    }

                    // If the data type is row version.
                    if (result.ColumnType.ToLower() == "timestamp")
                    {
                        tableEntityDataColumn.IsRowVersion = true;
                    }
                    else
                    {
                        tableEntityDataColumn.IsRowVersion = false;
                    }

                    // Assign the current data columns.
                    array[i++] = tableEntityDataColumn;
                }

                // Add all the data columns.
                _tableEntity.TableEntityDataColumn = array;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Add each query property.
        /// </summary>
        private void AddProperties()
        {
            if (_includeContextItems)
            {
                int propertyCount = 0;
                CodeMemberProperty endProperty = null;

                foreach (var table in _tables)
                {
                    if (_data.TableList.Contains(table.TableName.ToUpper(), new ToUpperComparer()) == !_tableListExclusion)
                    {
                        // Create a new property member
                        // and the accessor type.
                        CodeMemberProperty valueProperty = new CodeMemberProperty();
                        valueProperty.Attributes = MemberAttributes.Public | MemberAttributes.Final;

                        // Add the region directive if at the beginning
                        if (propertyCount == 0)
                        {
                            // Create a custom region.
                            CodeRegionDirective startRegion = new CodeRegionDirective(CodeRegionMode.Start, "Public Ling Properties");
                            valueProperty.StartDirectives.Add(startRegion);

                            // Increment the count.
                            propertyCount++;
                        }

                        // Assign the name and get and set indictors.
                        valueProperty.Name   = LinqToDataTypes.Plural(table.TableName);
                        valueProperty.HasGet = true;

                        // Add the comments to the property.
                        valueProperty.Comments.Add(new CodeCommentStatement("<summary>", true));
                        valueProperty.Comments.Add(new CodeCommentStatement("Gets, the " + table.TableName.ToLower() + " queryable provider property for the object.", true));
                        valueProperty.Comments.Add(new CodeCommentStatement("</summary>", true));

                        // Assign the property type for the property.
                        // Get the data type of the property from
                        // the sql data type.
                        valueProperty.Type = new CodeTypeReference("Nequeo.Data.Linq.Query<" +
                                                                   (!String.IsNullOrEmpty(_extendedName) ? "Data." + _extendedName + "." : "Data.") + table.TableName + ">");

                        // Add the code to the
                        // get section of the property.
                        valueProperty.GetStatements.Add(new CodeMethodReturnStatement(
                                                            new CodeFieldReferenceExpression(
                                                                new CodeThisReferenceExpression(), "GetTable<" +
                                                                (!String.IsNullOrEmpty(_extendedName) ? "Data." + _extendedName + "." : "Data.") + table.TableName + ">()")));

                        // Assign each property until the end.
                        endProperty = valueProperty;

                        // Add the property to the class.
                        _targetClass.Members.Add(valueProperty);
                    }
                }

                if (endProperty != null)
                {
                    // Create a custom endregion.
                    CodeRegionDirective endRegion = new CodeRegionDirective(CodeRegionMode.End, "");
                    endProperty.EndDirectives.Add(endRegion);
                }

                propertyCount = 0;
                endProperty   = null;

                // if a views exist.
                if (GetDatabaseViews())
                {
                    foreach (var view in _views)
                    {
                        if (_data.TableList.Contains(view.TableName.ToUpper(), new ToUpperComparer()) == !_tableListExclusion)
                        {
                            // Create a new property member
                            // and the accessor type.
                            CodeMemberProperty valueProperty = new CodeMemberProperty();
                            valueProperty.Attributes = MemberAttributes.Public | MemberAttributes.Final;

                            // Add the region directive if at the beginning
                            if (propertyCount == 0)
                            {
                                // Create a custom region.
                                CodeRegionDirective startRegion = new CodeRegionDirective(CodeRegionMode.Start, "Public Ling Properties");
                                valueProperty.StartDirectives.Add(startRegion);

                                // Increment the count.
                                propertyCount++;
                            }

                            // Assign the name and get and set indictors.
                            valueProperty.Name   = LinqToDataTypes.Plural(view.TableName);
                            valueProperty.HasGet = true;

                            // Add the comments to the property.
                            valueProperty.Comments.Add(new CodeCommentStatement("<summary>", true));
                            valueProperty.Comments.Add(new CodeCommentStatement("Gets, the " + view.TableName.ToLower() + " queryable provider property for the object.", true));
                            valueProperty.Comments.Add(new CodeCommentStatement("</summary>", true));

                            // Assign the property type for the property.
                            // Get the data type of the property from
                            // the sql data type.
                            valueProperty.Type = new CodeTypeReference("Nequeo.Data.Linq.Query<" +
                                                                       (!String.IsNullOrEmpty(_extendedName) ? "Data." + _extendedName + "." : "Data.") + view.TableName + ">");

                            // Add the code to the
                            // get section of the property.
                            valueProperty.GetStatements.Add(new CodeMethodReturnStatement(
                                                                new CodeFieldReferenceExpression(
                                                                    new CodeThisReferenceExpression(), "GetTable<" +
                                                                    (!String.IsNullOrEmpty(_extendedName) ? "Data." + _extendedName + "." : "Data.") + view.TableName + ">()")));

                            // Assign each property until the end.
                            endProperty = valueProperty;

                            // Add the property to the class.
                            _targetClass.Members.Add(valueProperty);
                        }
                    }
                }

                if (endProperty != null)
                {
                    // Create a custom endregion.
                    CodeRegionDirective endRegion = new CodeRegionDirective(CodeRegionMode.End, "");
                    endProperty.EndDirectives.Add(endRegion);
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Add each query property.
        /// </summary>
        private void AddProperties()
        {
            foreach (var table in _tables)
            {
                if (_data.TableList.Contains(table.TableName.ToUpper()) == !_tableListExclusion)
                {
                    // Create a new property member
                    // and the accessor type.
                    CodeMemberProperty valueProperty = new CodeMemberProperty();
                    valueProperty.Attributes = MemberAttributes.Public | MemberAttributes.Final;

                    // Assign the name and get and set indictors.
                    valueProperty.Name   = LinqToDataTypes.Plural(table.TableName);
                    valueProperty.HasGet = true;

                    // Add the comments to the property.
                    valueProperty.Comments.Add(new CodeCommentStatement("<summary>", true));
                    valueProperty.Comments.Add(new CodeCommentStatement("Gets, the " + table.TableName.ToLower() + " queryable provider property for the object.", true));
                    valueProperty.Comments.Add(new CodeCommentStatement("</summary>", true));

                    // Assign the property type for the property.
                    // Get the data type of the property from
                    // the sql data type.
                    valueProperty.Type = new CodeTypeReference("Nequeo.Data" + ".Linq.Data.QueryProvider.Query(Of " + (!String.IsNullOrEmpty(_extendedName) ? "Data." + _extendedName + "." : "Data.") + table.TableName + ")");

                    // Add the code to the
                    // get section of the property.
                    valueProperty.GetStatements.Add(new CodeMethodReturnStatement(
                                                        new CodeFieldReferenceExpression(
                                                            new CodeThisReferenceExpression(), "GetTable(Of " + (!String.IsNullOrEmpty(_extendedName) ? "Data." + _extendedName + "." : "Data.") + table.TableName + ")()")));

                    // Add the property to the class.
                    _targetClass.Members.Add(valueProperty);
                }
            }

            // if a views exist.
            if (GetDatabaseViews())
            {
                foreach (var view in _views)
                {
                    if (_data.TableList.Contains(view.TableName.ToUpper()) == !_tableListExclusion)
                    {
                        // Create a new property member
                        // and the accessor type.
                        CodeMemberProperty valueProperty = new CodeMemberProperty();
                        valueProperty.Attributes = MemberAttributes.Public | MemberAttributes.Final;

                        // Assign the name and get and set indictors.
                        valueProperty.Name   = LinqToDataTypes.Plural(view.TableName);
                        valueProperty.HasGet = true;

                        // Add the comments to the property.
                        valueProperty.Comments.Add(new CodeCommentStatement("<summary>", true));
                        valueProperty.Comments.Add(new CodeCommentStatement("Gets, the " + view.TableName.ToLower() + " queryable provider property for the object.", true));
                        valueProperty.Comments.Add(new CodeCommentStatement("</summary>", true));

                        // Assign the property type for the property.
                        // Get the data type of the property from
                        // the sql data type.
                        valueProperty.Type = new CodeTypeReference("Nequeo.Data" + ".Linq.Data.QueryProvider.Query(Of " + (!String.IsNullOrEmpty(_extendedName) ? "Data." + _extendedName + "." : "Data.") + view.TableName + ")");

                        // Add the code to the
                        // get section of the property.
                        valueProperty.GetStatements.Add(new CodeMethodReturnStatement(
                                                            new CodeFieldReferenceExpression(
                                                                new CodeThisReferenceExpression(), "GetTable(Of " + (!String.IsNullOrEmpty(_extendedName) ? "Data." + _extendedName + "." : "Data.") + view.TableName + ")()")));

                        // Add the property to the class.
                        _targetClass.Members.Add(valueProperty);
                    }
                }
            }
        }