private EntityProperties GetPrimaryKeyProperties(DataEntity dataEntity, OleDbMetadataAccess metadataAccess)
        {
            var primaryKeyProperties = new EntityProperties();
            //Use the data entity name to retrieve a list of indexes
            var indexColumns = metadataAccess.GetTableIndexInformation(dataEntity.ObjectDefinitionFullName);

            //Add each of the Primary Keys and their values found in the data entity.
            foreach (DataRow row in indexColumns.Rows)
            {
                if (!Convert.ToBoolean(row["PRIMARY_KEY"]))
                {
                    continue;
                }

                var columnName = row["COLUMN_NAME"].ToString();

                // Check if the priamry key column is included in the data entity.
                if (dataEntity.Properties.ContainsKey(columnName))
                {
                    // Add the key and its value to the primary key list.
                    primaryKeyProperties.Add(columnName, dataEntity.Properties[columnName]);
                }
                else
                {
                    // If the key has not been added set it to null.
                    primaryKeyProperties.Add(columnName, null);
                }
            }

            return(primaryKeyProperties);
        }
        /// <summary>
        /// Retrieves a list of column definitions for the specified table name.
        /// </summary>
        /// <param name="tableName">Name of the table to retrieve the properties for</param>
        /// <returns></returns>
        private List <IPropertyDefinition> GetTableProperties(string tableName)
        {
            List <IPropertyDefinition> properties = new List <IPropertyDefinition>();

            //retrieve the table's index information
            DataTable tableIndexDefinition =
                _metadataAccess.GetTableIndexInformation(tableName);

            //retrieve the table's column information
            DataTable columnDefinitions =
                _metadataAccess.GetColumnDefinitions(tableName);

            //parse through each of the table indexes and set the primary key value
            List <string> primaryKeys =
                (from DataRow tableIndex in tableIndexDefinition.Rows
                 where Convert.ToBoolean(tableIndex["PRIMARY_KEY"])
                 select tableIndex["COLUMN_NAME"].ToString()).ToList();

            //parse through the column information and set each property definition
            foreach (DataRow columnDefinition in columnDefinitions.Rows)
            {
                //get the property defintion using the column information
                var propertyDefinition = SetPropertyDefinition(columnDefinition, tableIndexDefinition,
                                                               primaryKeys.Contains(
                                                                   columnDefinition["COLUMN_NAME"].ToString()));
                properties.Add(propertyDefinition);
            }

            return(properties);
        }
Esempio n. 3
0
        private EntityProperties GetPrimaryKeyProperties(DataEntity dataEntity, OleDbMetadataAccess metadataAccess)
        {
            var primaryKeyProperties = new EntityProperties();
            //Use the data entity name to retrieve a list of indexes
            var indexColumns = metadataAccess.GetTableIndexInformation(dataEntity.ObjectDefinitionFullName);

            //Add each of the Primary Keys and their values found in the data entity.
            foreach (DataRow row in indexColumns.Rows)
            {
                if (!Convert.ToBoolean(row["PRIMARY_KEY"]))
                {
                    continue;
                }

                var columnName = row["COLUMN_NAME"].ToString();

                // Check if the priamry key column is included in the data entity.
                if (dataEntity.Properties.ContainsKey(columnName))
                {
                    // Add the key and its value to the primary key list.
                    primaryKeyProperties.Add(columnName, dataEntity.Properties[columnName]);
                }
                else
                {
                    // If the key has not been added set it to null.
                    primaryKeyProperties.Add(columnName, null);
                }
            }

            return primaryKeyProperties;
        }