예제 #1
0
        public Database.Database GetSchema(string connectionString)
        {
            this.connectionString = connectionString;

            this.database = new Database.Database();

            this.resourceFileManager = new ResourceFileManager();

            DataSet ds = this.GetSchemaDataSet();

            this.LoadDatabaseSchema(ds);

            this.InitializeDescriptionForEnumColumn();

            return(this.database);
        }
예제 #2
0
        public static Mapping CreateMapping(string mappingConfigFile, string mappingConfigContent)
        {
            mappingConfig = new MappingConfiguration(mappingConfigContent);

            string configFile = Path.Combine(Path.GetDirectoryName(mappingConfigFile), mappingConfig.ConfigFile);

            string connectionStringName  = GetConnectionStringName(mappingConfigFile);
            string connectionStringValue = GetConnectionStringValue(configFile, connectionStringName);

            provider = new SchemaProvider();

            database = provider.GetSchema(connectionStringValue);

            mapping = GetMapping(database, mappingConfig, connectionStringName);

            ////MappingExtender extender = new MappingExtender(mapping);

            ////extender.Extend();

            return(mapping);
        }
예제 #3
0
        private static Mapping GetMapping(Database.Database database, MappingConfiguration mappingConfig, string connectionStringName)
        {
            string schema;

            mapping = new Mapping();
            mapping.ConnectionStringName = connectionStringName;
            mapping.Database             = database;

            foreach (var enumeration in database.Enumerations)
            {
                DbSharper.Schema.Code.Enum enm = new DbSharper.Schema.Code.Enum
                {
                    Name              = enumeration.Name,
                    BaseType          = enumeration.BaseType,
                    HasFlagsAttribute = enumeration.HasFlagsAttribute,
                    Description       = enumeration.Description
                };

                LoadEnumMembers(enm.Members, enumeration);

                mapping.Enums.Add(enm);
            }

            foreach (Table table in database.Tables)
            {
                if (mappingConfig.Model.IsIncluded(table))
                {
                    schema = MappingHelper.GetPascalCase(table.Schema);

                    if (!mapping.ModelNamespaces.Contains(schema))
                    {
                        mapping.ModelNamespaces.Add(new ModelNamespace()
                        {
                            Name = schema
                        });
                    }

                    Model model = new Model()
                    {
                        Name          = MappingHelper.GetPascalCase(mappingConfig.Model.TrimName(table)),
                        Description   = table.Description,
                        Schema        = MappingHelper.GetPascalCase(table.Schema),
                        IsView        = false,
                        MappingSource = table.Name
                    };

                    LoadProperties(model.Properties, table);

                    mapping.ModelNamespaces[schema].Models.Add(model);
                }
            }

            foreach (View view in database.Views)
            {
                if (mappingConfig.Model.IsIncluded(view))
                {
                    schema = MappingHelper.GetPascalCase(view.Schema);

                    if (!mapping.ModelNamespaces.Contains(schema))
                    {
                        mapping.ModelNamespaces.Add(new ModelNamespace()
                        {
                            Name = schema
                        });
                    }

                    Model model = new Model()
                    {
                        Name          = MappingHelper.GetPascalCase(mappingConfig.Model.TrimName(view)),
                        Description   = view.Description,
                        Schema        = MappingHelper.GetPascalCase(view.Schema),
                        IsView        = true,
                        MappingSource = view.Name
                    };

                    LoadProperties(model.Properties, view);

                    mapping.ModelNamespaces[schema].Models.Add(model);
                }
            }

            foreach (StoredProcedure procedure in database.StoredProcedures)
            {
                if (mappingConfig.DataAccess.IsIncluded(procedure))
                {
                    var classMethod = mappingConfig.DataAccess.GetClassMethod(procedure);

                    if (classMethod == null)
                    {
                        continue;
                    }

                    schema = MappingHelper.GetPascalCase(procedure.Schema);

                    if (!mapping.DataAccessNamespaces.Contains(schema))
                    {
                        mapping.DataAccessNamespaces.Add(new DataAccessNamespace()
                        {
                            Name = schema
                        });
                    }

                    if (!mapping.DataAccessNamespaces[schema].DataAccesses.Contains(classMethod.ClassName))
                    {
                        mapping.DataAccessNamespaces[schema].DataAccesses.Add(
                            new DataAccess()
                        {
                            Name        = classMethod.ClassName,
                            Description = string.Format(CultureInfo.InvariantCulture, "Access data about {0}.", classMethod.ClassName),
                            Schema      = MappingHelper.GetPascalCase(procedure.Schema)
                        });
                    }

                    ////if ((classMethod.MethodName == "Create" || classMethod.MethodName == "Update") && mapping.GetModel(classMethod.ClassName) != null)
                    ////{
                    ////    continue;
                    ////}

                    mapping.DataAccessNamespaces[schema].DataAccesses[classMethod.ClassName].Methods.Add(
                        BuildMethod(procedure, classMethod.ClassName, classMethod.MethodName));
                }
            }

            return(mapping);
        }