/// <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; }
public void GetTableDescriptorFrom_Always_CreatesTheTableDescriptor() { var propertyMetadata = new DbPropertyMetadata( "dbo", "MyTable", "Id", "int", false); TableDescriptor table = processor.GetTableDescriptorFrom(propertyMetadata, true); Assert.AreEqual(table.Name, "MyTable"); Assert.AreEqual(table.Schema, "dbo"); }
public void GetTableDescriptorFrom_WhenCalledWithExistingTableData_ReturnsTheExistingTable() { var property1 = new DbPropertyMetadata( "dbo", "MyTable", "Id", "int", false); var property2 = new DbPropertyMetadata( "dbo", "MyTable", "Name", "string", false); TableDescriptor table1 = processor.GetTableDescriptorFrom(property1, true); TableDescriptor table2 = processor.GetTableDescriptorFrom(property2, true); Assert.AreEqual(table1, table2); }
/// <summary> /// Add a <paramref name="property"/> to the table /// </summary> /// <param name="property">The property to add</param> public void Add(DbPropertyMetadata property) { if (properties.ContainsKey(property.Column)) throw new ArgumentException(string.Format( "Duplicate property found: {0}.{1}", Name, property.Column), "property"); properties.Add(property.Column, property); }
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); }
/// <summary> /// Processes metadata /// </summary> /// <param name="propertyMetadata">property</param> /// <param name="schemaInClassName">schema</param> public void Process(DbPropertyMetadata propertyMetadata, bool schemaInClassName) { TableDescriptor table = GetTableDescriptorFrom(propertyMetadata, schemaInClassName); table.Add(propertyMetadata); }