Example #1
0
 protected void AddProperties(PocoEntity result, WType type)
 {
     PropertyToPocoField converter = this.factory.GetPropertyToPocoField();
     foreach (WProperty property in type.GetProperties())
     {
         if (property.GetAttribute<WormIgnoreAttribute>() == default(WormIgnoreAttribute))
         {
             result.Fields.Add(converter.Parse(property));
         }
     }
 }
        public void Test()
        {
            var dbClassWriter = new DbClassWriter(new WormFactory());
            var entity = new PocoEntity() {
                DbFactory = new MySqlWormDbFactory(String.Empty),
                PocoClassName = "TestEntity",
                PocoFilename = "TestEntity.cs",
                PocoNamespace = "Test.Entities",
                TableName = "test_entities",
                WormClassName = "WormTestEntity",
                WormFilename = "WormTestEntity.cs",
                WormNamespace = "Test.Entities.Db"
            };

            entity.Fields.Add(new PocoField() {
                AccessModifier = AccessModifier.Public,
                ColumnName = "id",
                HasGetter = true,
                HasSetter = true,
                IdGenerator = WormIdGenerator.AutoIncrement,
                IsPrimaryKey = true,
                Name = "Id",
                StorageType = "int",
                Type = "int"
            });

            entity.Fields.Add(new PocoField() {
                AccessModifier = AccessModifier.Public,
                ColumnName = "my_string",
                HasGetter = true,
                HasSetter = true,
                Name = "MyString",
                StorageType = "varchar(255)",
                Type = "string"
            });

            entity.Fields.Add(new PocoField() {
                AccessModifier = AccessModifier.Public,
                ColumnName = "my_int",
                HasGetter = true,
                HasSetter = true,
                Name = "MyInt",
                StorageType = "int",
                Type = "int"
            });

            var result = dbClassWriter.Generate(entity);

            System.IO.File.WriteAllText("/tmp/mysql_" + result.Filename, result.Content);

            Assert.AreEqual("WormTestEntity.cs", result.Filename);
        }
Example #3
0
        public CodeFile Generate(PocoEntity model)
        {
            var template = this.factory.GetWormDbClassTemplate();
            template.Model = model;

            var provider = model.DbFactory.GetTemplateProvider();

            template.DbGetByIdOrDefaultTemplate = provider.GetDbGetByIdOrDefaultTemplate();
            template.DbGetByIdOrDefaultTemplate.Poco = model;

            template.DbInsertTemplate = provider.GetDbInsertTemplate();
            template.DbInsertTemplate.Poco = model;

            template.DbUpdateTemplate = provider.GetDbUpdateTemplate();
            template.DbUpdateTemplate.Poco = model;

            return new CodeFile() {
                Filename = model.WormFilename,
                Content = template.TransformText()
            };
        }