public ActiveRecordDescriptor Build(TableDefinition tableDef, BuildContext context) { ActiveRecordDescriptor desc = ObtainDescriptor(tableDef); // ClassName desc.ClassName = _namingService.CreateClassName(tableDef.Name); // Plain fields desc.Properties.AddRange(_plainFieldsService.InferProperties(tableDef)); // Relations desc.PropertiesRelations.AddRange(_relationsService.InferRelations(desc, tableDef, context)); // Operations // TODO! context.RemovePendent(desc); Build(context); return(desc); }
public void CreateClassName() { INamingService service = (INamingService)Kernel[typeof(INamingService)]; Assert.AreEqual("Author", service.CreateClassName("authors")); Assert.AreEqual("Tax", service.CreateClassName("Taxes")); Assert.AreEqual("Child", service.CreateClassName("children")); Assert.AreEqual("Order", service.CreateClassName("Orders")); Assert.AreEqual("Order", service.CreateClassName("Order")); Assert.AreEqual("Order", service.CreateClassName("_Order")); Assert.AreEqual("Order", service.CreateClassName("tb_Order")); Assert.AreEqual("Order", service.CreateClassName("tb_Orders")); }
public override void Activated(System.Collections.IDictionary context) { TableDefinition table = context["selectedtable"] as TableDefinition; if (table != _oldTable) { _oldTable = table; INamingService naming = ServiceRegistry.Instance[typeof(INamingService)] as INamingService; className.Text = naming.CreateClassName(table.Name); } }
private void CreateBelongsToRelations(ActiveRecordDescriptor desc, TableDefinition tableDef, IList list, BuildContext context) { foreach (ColumnDefinition col in tableDef.Columns) { if (col.RelatedTable != null) { bool pendentNecessary = false; String propertyName = _namingService.CreateClassName(col.RelatedTable.Name); ActiveRecordDescriptor targetType = null; if (col.RelatedTable.RelatedDescriptor == null && col.RelatedTable != tableDef) { col.RelatedTable.RelatedDescriptor = new ActiveRecordDescriptor(col.RelatedTable); pendentNecessary = true; } else if (col.RelatedTable == tableDef) { targetType = desc; } if (targetType == null) { targetType = col.RelatedTable.RelatedDescriptor; } ActiveRecordBelongsToDescriptor belongsTo = new ActiveRecordBelongsToDescriptor(col.Name, propertyName, targetType); list.Add(belongsTo); if (pendentNecessary) { context.AddPendentDescriptor(belongsTo, col.RelatedTable.RelatedDescriptor); } } } }