public void BlogPlainFields()
        {
            Kernel.AddComponent("plainfields", typeof(IPlainFieldInferenceService), typeof(PlainFieldInferenceService));
            Kernel.AddComponent("nameService", typeof(INamingService), typeof(NamingService));
            Kernel.AddComponent("typeinf", typeof(ITypeInferenceService), typeof(TypeInferenceService));

            IPlainFieldInferenceService plainService = Kernel[typeof(IPlainFieldInferenceService)] as IPlainFieldInferenceService;

            TableDefinition table = new TableDefinition("blogs", new DatabaseDefinition("alias"));

            table.AddColumn(new ColumnDefinition("id", true, false, true, false, OleDbType.Integer));
            table.AddColumn(new ColumnDefinition("name", false, false, false, false, OleDbType.VarChar));
            table.AddColumn(new ColumnDefinition("authorid", false, true, false, false, OleDbType.VarChar));

            ActiveRecordPropertyDescriptor[] descs = plainService.InferProperties(table);

            Assert.IsNotNull(descs);
            Assert.AreEqual(2, descs.Length);

            ActiveRecordPropertyDescriptor desc1 = descs[0];
            ActiveRecordPropertyDescriptor desc2 = descs[1];

            Assert.AreEqual("id", desc1.ColumnName);
            Assert.AreEqual("Integer", desc1.ColumnTypeName);
            Assert.AreEqual("Id", desc1.PropertyName);
            Assert.AreEqual(typeof(int), desc1.PropertyType);

            Assert.AreEqual("name", desc2.ColumnName);
            Assert.AreEqual("VarChar", desc2.ColumnTypeName);
            Assert.AreEqual("Name", desc2.PropertyName);
            Assert.AreEqual(typeof(String), desc2.PropertyType);
        }
Beispiel #2
0
        public override void Activated(IDictionary context)
        {
            TableDefinition table = context["selectedtable"] as TableDefinition;

            if (table != _oldTable)
            {
                _oldTable = table;

                IPlainFieldInferenceService fieldInference = ServiceRegistry.Instance[typeof(IPlainFieldInferenceService)] as IPlainFieldInferenceService;

                ActiveRecordPropertyDescriptor[] properties =
                    fieldInference.InferProperties(table);

                ActiveRecordDescriptor ar = context["ardesc"] as ActiveRecordDescriptor;
                ar.Properties.Clear();
                ar.Properties.AddRange(properties);

                listView1.Items.Clear();

                foreach (ActiveRecordPropertyDescriptor desc in properties)
                {
                    ListViewItem item = listView1.Items.Add(desc.PropertyName);
                    item.Tag     = desc;
                    item.Checked = desc.Generate;
                    item.SubItems.Add(desc.PropertyType.Name);
                    item.SubItems.Add(desc.ColumnName);
                    item.SubItems.Add(desc.ColumnTypeName);
                }
            }
        }
Beispiel #3
0
        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);
        }