示例#1
0
        private string GetFileName(ProjectViewModel project, EntitiesGen item)
        {
            var p = ".";

            project.FileSuffix = project.FileSuffix.TrimStart('.');
            if (project.FileSuffix.Contains("."))
            {
                p = null;
            }
            return(FileSugar.MergeUrl(project.Path, item.ClassName + p + project.FileSuffix));
        }
示例#2
0
        private string GetFileName(Project project, EntitiesGen item)
        {
            var    p    = ".";
            string name = item.ClassName;

            project.FileSuffix = project.FileSuffix.TrimStart('.');
            if (project.FileSuffix.Contains("."))
            {
                p = null;
            }
            if (project.NameFormat != null && project.NameFormat.Contains("@(") && project.NameFormat.Contains(")"))
            {
                var format = project.NameFormat.Replace("{0}", "Model.ClassName");
                name = TemplateHelper.GetTemplateValue(project.NameFormat + "format", format, item);
            }
            else if (!string.IsNullOrEmpty(project.NameFormat))
            {
                name = string.Format(project.NameFormat, item.ClassName);
            }
            return(FileSugar.MergeUrl(project.Path, name + p + project.FileSuffix));
        }
示例#3
0
        private List <EntitiesGen> GetGenList(List <CodeTable> tableList, List <CodeType> types, SqlSugar.DbType databasedbType)
        {
            List <EntitiesGen> result = new List <EntitiesGen>();
            var mapping = Db.Queryable <MappingProperty>().ToList();
            var tags    = Db.Queryable <TagProperty>().ToList();

            if (databasedbType == DbType.MySql)
            {
                var timestamp = types.FirstOrDefault(it => it.Name == "timestamp");
                if (timestamp != null)
                {
                    timestamp.CSharepType = "DateTime";
                }
            }
            foreach (var item in tableList)
            {
                EntitiesGen gen = new EntitiesGen()
                {
                    ClassName    = item.ClassName,
                    Description  = item.Description,
                    TableName    = item.TableName,
                    PropertyGens = new List <PropertyGen>()
                };
                foreach (var column in base.CodeColumnsDb.GetList(it => it.CodeTableId == item.Id))
                {
                    var codeType = types.First(it => it.Name == column.CodeType);
                    if (codeType.Id == 3)
                    {
                        PropertyGen proGen = new PropertyGen()
                        {
                            DbColumnName  = column.DbColumnName,
                            Description   = column.Description,
                            IsIdentity    = column.IsIdentity,
                            IsPrimaryKey  = column.IsPrimaryKey,
                            PropertyName  = GetPropertyName(column.ClassProperName),
                            Type          = GetType(column),
                            IsNullable    = column.Required == false,
                            DbType        = "",
                            Length        = 0,
                            DecimalDigits = 0,
                            IsIgnore      = true,
                            CodeType      = column.CodeType,
                            DefaultValue  = column.DefaultValue
                        };
                        var mappings = mapping.Where(it => item.DbId == it.DbId && it.TableName == item.ClassName && it.ColumnName == column.ClassProperName).ToList();;
                        proGen.MappingProperties = tags.Where(it => mappings.Any(x => x.TagId == it.Id + "")).ToList();
                        gen.PropertyGens.Add(proGen);
                    }
                    else
                    {
                        var         dbType = GetTypeInfoByDatabaseType(codeType.DbType, databasedbType);
                        PropertyGen proGen = new PropertyGen()
                        {
                            DbColumnName  = column.DbColumnName,
                            Description   = column.Description,
                            IsIdentity    = column.IsIdentity,
                            IsPrimaryKey  = column.IsPrimaryKey,
                            PropertyName  = GetPropertyName(column.ClassProperName),
                            Type          = IsSpecialType(column) ? GetType(column) : codeType.CSharepType,
                            IsNullable    = column.Required == false,
                            DbType        = dbType.Name,
                            Length        = dbType.Length,
                            DecimalDigits = dbType.DecimalDigits,
                            IsSpecialType = IsSpecialType(column),
                            CodeType      = column.CodeType,
                            DefaultValue  = column.DefaultValue
                        };
                        var mappings = mapping.Where(it => item.DbId == it.DbId && it.TableName == item.ClassName && it.ColumnName == column.ClassProperName).ToList();;
                        proGen.MappingProperties = tags.Where(it => mappings.Any(x => x.TagId == it.Id + "")).ToList();
                        gen.PropertyGens.Add(proGen);
                    }
                }
                result.Add(gen);
            }
            return(result);
        }