コード例 #1
0
        public void PostBelongsToBlog()
        {
            InitKernel();
            IRelationshipInferenceService relService = ObtainService();

            TableDefinition blogTable;
            TableDefinition postTable;

            BuildBlogPostsStructure(out blogTable, out postTable);

            BuildContext context = new BuildContext();

            ActiveRecordDescriptor arDesc = new ActiveRecordDescriptor();

            ActiveRecordPropertyDescriptor[] descs = relService.InferRelations(arDesc, postTable, context);

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

            ActiveRecordBelongsToDescriptor desc1 = descs[0] as ActiveRecordBelongsToDescriptor;

            Assert.IsNotNull(desc1);
            Assert.IsNotNull(desc1.TargetType);
            Assert.IsNull(desc1.PropertyType);

            Assert.AreEqual("Blog", desc1.PropertyName);
            Assert.AreEqual("blog_id", desc1.ColumnName);

            ActiveRecordDescriptor targetARDescriptor = context.GetNextPendent();

            Assert.AreSame(blogTable, targetARDescriptor.Table);
        }
コード例 #2
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);
        }
コード例 #3
0
        public override void Activated(IDictionary context)
        {
            TableDefinition table = context["selectedtable"] as TableDefinition;

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

                ActiveRecordDescriptor ar = context["ardesc"] as ActiveRecordDescriptor;

                listView1.Items.Clear();

                BuildContext buildCtx = context["buildcontext"] as BuildContext;

                IRelationshipInferenceService relationInference =
                    ServiceRegistry.Instance[typeof(IRelationshipInferenceService)] as IRelationshipInferenceService;

                ActiveRecordPropertyRelationDescriptor[] properties =
                    relationInference.InferRelations(ar, table, buildCtx);

                ar.PropertiesRelations.Clear();
                ar.PropertiesRelations.AddRange(properties);

                foreach (ActiveRecordPropertyRelationDescriptor property in properties)
                {
                    ListViewItem item = listView1.Items.Add(property.PropertyName);
                    item.Tag     = property;
                    item.Checked = property.Generate;

                    if (property.TargetType != null)
                    {
                        item.SubItems.Add(
                            property.TargetType.ClassName != null ? property.TargetType.ClassName : "<Pendent>");
                    }
                    else
                    {
                        throw new ApplicationException("Information missing");
                    }

                    item.SubItems.Add(property.RelationType);
                    item.SubItems.Add(property.ColumnName);
                }
            }
        }
コード例 #4
0
        public void SelfReference()
        {
            InitKernel();
            IRelationshipInferenceService relService = ObtainService();

            DatabaseDefinition dbdef = new DatabaseDefinition("alias");

            TableDefinition categoryTable = new TableDefinition("categories", dbdef);

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

            categoryTable.AddManyRelation(categoryTable);

            BuildContext context = new BuildContext();

            ActiveRecordDescriptor arDesc = new ActiveRecordDescriptor();

            ActiveRecordPropertyDescriptor[] descs = relService.InferRelations(arDesc, categoryTable, context);

            Assert.IsFalse(context.HasPendents);

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

            ActiveRecordHasManyDescriptor desc1 = descs[0] as ActiveRecordHasManyDescriptor;

            Assert.IsNotNull(desc1);
            Assert.IsNotNull(desc1.TargetType);
            Assert.IsNotNull(desc1.PropertyType);

            Assert.AreEqual("Categories", desc1.PropertyName);
            Assert.AreEqual("parent_id", desc1.ColumnName);
            Assert.AreEqual(typeof(IList), desc1.PropertyType);

            ActiveRecordBelongsToDescriptor desc2 = descs[1] as ActiveRecordBelongsToDescriptor;

            Assert.IsNotNull(desc2);
            Assert.IsNotNull(desc2.TargetType);
            Assert.IsNull(desc2.PropertyType);
            Assert.AreEqual("Category", desc2.PropertyName);
            Assert.AreEqual("parent_id", desc2.ColumnName);
        }