Example #1
0
        private static string ResolvePropertyName(ScaffoldObject obj, ColumnModel column)
        {
            string propertyName = CSharp.Identifier(column.Name);

            if (propertyName == obj.ClassName)
            {
                return($"{propertyName}0");
            }

            return(propertyName);
        }
Example #2
0
        public static ScaffoldProject FromModel(DatabaseModel databaseModel, IList <TypeMapping> typeMappings, RunnerArgs args)
        {
            List <ScaffoldFile> files = new List <ScaffoldFile>();

            foreach (var g1 in databaseModel.Tables.GroupBy(t => ResolveFileName(t, databaseModel.DefaultSchema, args)))
            {
                ScaffoldFile newFile = new ScaffoldFile()
                {
                    FileName = g1.Key,
                };

                foreach (TableModel table in g1.Where(t => !t.Ignore))
                {
                    ScaffoldObject newObject = new ScaffoldObject()
                    {
                        Table     = table,
                        Namespace = ResolveNamespace(table, databaseModel.DefaultSchema, args),
                        ClassName = ResolveClassName(table),
                    };

                    foreach (ColumnModel column in table.Columns.Where(c => !c.Ignore))
                    {
                        ScaffoldProperty newProperty = new ScaffoldProperty()
                        {
                            Column       = column,
                            PropertyName = ResolvePropertyName(newObject, column),
                            TypeName     = ResolveTypeName(typeMappings, column),
                        };

                        newObject.Properties.Add(newProperty);
                    }

                    newFile.Objects.Add(newObject);
                }

                if (newFile.Objects.Count > 0)
                {
                    files.Add(newFile);
                }
            }

            return(new ScaffoldProject()
            {
                Files = files,
                Database = databaseModel,
            });
        }