private void BuildBlogPostsStructure(out TableDefinition blogTable, out TableDefinition postTable)
        {
            DatabaseDefinition dbdef = new DatabaseDefinition("alias");

            blogTable = new TableDefinition("blogs", dbdef);
            blogTable.AddColumn(new ColumnDefinition("id", true, false, true, false, OleDbType.Integer));
            blogTable.AddColumn(new ColumnDefinition("name", false, false, false, false, OleDbType.VarChar));

            postTable = new TableDefinition("posts", dbdef);
            postTable.AddColumn(new ColumnDefinition("id", true, false, true, false, OleDbType.Integer));
            postTable.AddColumn(new ColumnDefinition("name", false, false, false, false, OleDbType.VarChar));
            postTable.AddColumn(new ColumnDefinition("blog_id", false, true, false, false, OleDbType.VarChar, blogTable));

            blogTable.AddManyRelation(postTable);
        }
Exemple #2
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);
        }