Beispiel #1
0
        /// <summary>
        /// Extracts a <see cref="TableDescriptor"/> out of a metadata
        /// </summary>
        /// <param name="propertyMetadata">property</param>
        /// <param name="schemaInClassName">schema</param>
        /// <returns><see cref="TableDescriptor"/></returns>
        public TableDescriptor GetTableDescriptorFrom(DbPropertyMetadata propertyMetadata, bool schemaInClassName)
        {
            var table = new TableDescriptor(propertyMetadata.Schema, propertyMetadata.Table, schemaInClassName);
            if (tables.ContainsKey(table.ClassName))
                return tables[table.ClassName];

            tables.Add(table.ClassName, table);
            return table;
        }
Beispiel #2
0
        private static string GetClassesFrom(TableDescriptor table)
        {
            StringBuilder classes = new StringBuilder()
                .AppendLine(GetTableClassFrom(table));
            foreach (DbPropertyMetadata property in table.Properties)
            {
                classes.AppendLine(GetPropertyClassFrom(table, property));
            }

            return classes.ToString();
        }
Beispiel #3
0
        private static string GetTableClassFrom(TableDescriptor table)
        {
            return string.Format(
                @"	public class {2} : D9.SQLQueryGenerator.Runtime.Model.Table.AbstractTable
            {{
            public {2}(string alias) : base(""{0}"", ""{1}"", alias)
            {{
            {3}
            }}

            public {2}() : this(null)
            {{
            }}

            {4}

            public {2} As(string alias)
            {{
            return new {2}(alias);
            }}
            }}",
                table.Schema, table.Name, table.ClassName, GetFieldInitializersFor(table), GetFieldDeclerationsFor(table));
        }
Beispiel #4
0
 private static string GetPropertyClassFrom(TableDescriptor table, DbPropertyMetadata property)
 {
     return string.Format(
         @"	public class {0}_{1} : D9.SQLQueryGenerator.Runtime.Model.Field.AbstractField<{2}>
     {{
     public {0}_{1}(D9.SQLQueryGenerator.Runtime.Model.Table.AbstractTable table)
     : base(table, ""{1}"")
     {{
     }}
     }}",
         table.ClassName, property.Column, property.Type.FullName);
 }
Beispiel #5
0
        private static string GetFieldInitializersFor(TableDescriptor table)
        {
            var initializers = new List<string>(table.Properties.Count);
            foreach (DbPropertyMetadata property in table.Properties)
            {
                initializers.Add(string.Format(
                                 	@"			{0} = new {1}_{2}(this);",
                                 	property.Column, table.ClassName, property.Column));
            }

            return string.Join(Environment.NewLine, initializers.ToArray());
        }
Beispiel #6
0
        private static string GetFieldDeclerationsFor(TableDescriptor table)
        {
            var declerations = new List<string>(table.Properties.Count);
            foreach (DbPropertyMetadata property in table.Properties)
            {
                declerations.Add(string.Format(
                                 	@"		public readonly {1}_{2} {0};",
                                 	property.Column, table.ClassName, property.Column));
            }

            return string.Join(Environment.NewLine, declerations.ToArray());
        }