Ejemplo n.º 1
0
        public void WriteEntity(DataBaseTable item)
        {
            var path = Path.Combine(Config.CSharp.EntityFramework.Path, item.Schema);
            var file = $"{item.Name}.cs";

            var nameSpace = new List <string> {
                "System", "System.Collections.Generic"
            };

            nameSpace.AddRange(item.RelationShips.Where(c => c.TableFK != item.Schema).Select(c => $"{Config.CSharp.EntityFramework.NameSpace}.{c.SchemaFK}").Distinct());
            nameSpace.AddRange(item.RelationShips.Where(c => c.TablePK != item.Schema).Select(c => $"{Config.CSharp.EntityFramework.NameSpace}.{c.SchemaPK}").Distinct());
            nameSpace.AddRange(item.Columns.Where(c => c.Schema != item.Schema).Select(c => c.Schema));
            nameSpace.AddRange(item.ProcessRemapSchema(Config));


            var itemNameSpace = $"{Config.CSharp.EntityFramework.NameSpace}.{item.Schema}";

            nameSpace.RemoveAll(c => c == itemNameSpace);

            var builder = new StringBuilderIndented();

            builder
            .GenerateFileMessage()
            .ClassInit(item.Name, null, itemNameSpace, ClassVisility.Public, nameSpace.ToArray());

            foreach (var property in item.Columns)
            {
                var propertyType = property.ProcessRemapProperty(Config);

                builder
                .AppendLine($"public {propertyType} {property.Name} {{ get; set; }}")
                .AppendLine();
            }

            foreach (var relationShip in item.RelationShips.Where(c => c.Type == DataBaseRelationShipType.Single))
            {
                var relationShipName = ProcessRelationShipName(relationShip, relationShip.TablePK);

                builder
                .AppendLine($"public virtual {relationShip.TablePK} {relationShipName} {{ get; set; }}")
                .AppendLine();
            }

            foreach (var relationShip in item.RelationShips.Where(c => c.Type == DataBaseRelationShipType.Many))
            {
                var relationShipName = ProcessRelationShipName(relationShip, relationShip.TableFK);

                builder
                .AppendLine($"public virtual ICollection<{relationShip.TableFK}> {relationShipName} {{ get; set; }}")
                .AppendLine();
            }

            builder
            .ClassEnd();

            Writer.WriteFile(path, file, builder, true);
        }
Ejemplo n.º 2
0
        public void WriteEntity(DataBaseTable item)
        {
            var path = Path.Combine(Config.CSharp.Entity.Path, item.Schema, "Auto");
            var file = $"{item.Name}Entity.cs";

            var nameSpace = new List <string> {
                "System", "XCommon.Patterns.Repository.Entity", "System.Runtime.Serialization"
            };

            nameSpace.AddRange(item.Columns.Where(c => c.Schema != item.Schema).Select(c => c.Schema));
            nameSpace.AddRange(item.ProcessRemapSchema(Config));

            var builder = new StringBuilderIndented();

            builder
            .GenerateFileMessage()
            .ClassInit($"{item.Name}Entity", "EntityBase", $"{Config.CSharp.Entity.NameSpace}.{item.Schema}", ClassVisility.Public, true, nameSpace.ToArray());

            foreach (var column in item.Columns)
            {
                var propertyType = column.ProcessRemapProperty(Config);

                builder
                .AppendLine($"public {propertyType} {column.Name} {{ get; set; }}")
                .AppendLine();
            }

            builder
            .AppendLine()
            .AppendLine("[IgnoreDataMember]")
            .AppendLine("public override Guid Key")
            .AppendLine("{")
            .IncrementIndent()
            .AppendLine("get")
            .AppendLine("{")
            .IncrementIndent()
            .AppendLine($"return {item.PKName};")
            .DecrementIndent()
            .AppendLine("}")
            .AppendLine("set")
            .AppendLine("{")
            .IncrementIndent()
            .AppendLine($"{item.PKName} = value;")
            .DecrementIndent()
            .AppendLine("}")
            .DecrementIndent()
            .AppendLine("}")
            .ClassEnd();

            Writer.WriteFile(path, file, builder, true);
        }