Beispiel #1
0
        public void CreateOrmAssembly(
            bool saveOrmAssembly,
            string ormAssemblyOutputDirectory)
        {
            string assemblyFileName = string.Format("{0}.dll", this.Name);

            _ormAssembly = new OrmAssemblyWindows(
                this.Name,
                assemblyFileName,
                AssemblyBuilderAccess.RunAndSave);
            foreach (DatabaseTableWindows table in _tables)
            {
                OrmTypeWindows ormType = _ormAssembly.CreateOrmType(table.TableName, true);
                PublishFeedback(string.Format("Created type {0}.", ormType.TypeName));
                foreach (DatabaseTableColumnWindows column in table.Columns)
                {
                    ormType.CreateOrmProperty(
                        column.ColumnName,
                        SqlTypeConverterWindows.Instance.GetDotNetType(column.DataType, column.IsNullable));
                }
                table.MappedType = ormType.CreateType();
            }
            if (!saveOrmAssembly)
            {
                return;
            }
            _ormAssembly.Save(ormAssemblyOutputDirectory);
        }
        public OrmTypeWindows CreateOrmTypeFromSqlDataReader(
            string typeName,
            DbDataReader reader,
            bool prefixWithAssemblyNamespace)
        {
            DataTable      schemaTable = reader.GetSchemaTable();
            OrmTypeWindows result      = CreateOrmType(typeName, prefixWithAssemblyNamespace);

            foreach (DataRow r in schemaTable.Rows)
            {
                string columnName      = r[COLUMN_NAME_SCHEMA_ATTRIBUTE].ToString();
                short  ordinalPosition = Convert.ToInt16(r[ORDINAL_POSITION_SCHEMA_ATTRIBUTE]);
                bool   isNullable      = bool.Parse(r[IS_NULLABLE_SCHEMA_ATTRIBUTE].ToString());
                string dataTypeName    = r[DATA_TYPE_NAME_SCHEMA_ATTRIBUTE].ToString();
                result.CreateOrmProperty(
                    columnName,
                    SqlTypeConverterWindows.Instance.GetDotNetType(dataTypeName, isNullable));
            }
            result.CreateType();
            return(result);
        }
        public static Type GenerateType(
            string assemblyName,
            string typeName,
            DataTable schemaTable,
            bool prefixWithAssemblyNamespace)
        {
            OrmAssemblyWindows assembly = new OrmAssemblyWindows(assemblyName, AssemblyBuilderAccess.Run);
            OrmTypeWindows     type     = assembly.CreateOrmType(typeName, prefixWithAssemblyNamespace);

            foreach (DataRow row in schemaTable.Rows)
            {
                string columnName      = row[COLUMN_NAME_SCHEMA_ATTRIBUTE].ToString();
                short  ordinalPosition = Convert.ToInt16(row[ORDINAL_POSITION_SCHEMA_ATTRIBUTE]);
                bool   isNullable      = bool.Parse(row[IS_NULLABLE_SCHEMA_ATTRIBUTE].ToString());
                string dataTypeName    = row[DATA_TYPE_NAME_SCHEMA_ATTRIBUTE].ToString();
                type.CreateOrmProperty(
                    columnName,
                    SqlTypeConverterWindows.Instance.GetDotNetType(dataTypeName, isNullable),
                    System.Reflection.PropertyAttributes.HasDefault);
            }
            Type result = type.CreateType();

            return(result);
        }