public void HasMany() { InitKernel(); IRelationshipBuilder relService = ObtainService(); TableDefinition blogTable; TableDefinition postTable; BuildBlogPostsStructure(out blogTable, out postTable); ActiveRecordDescriptor desc = new ActiveRecordDescriptor("Blog"); ActiveRecordDescriptor targetDesc = new ActiveRecordDescriptor("Post"); RelationshipInfo info = new RelationshipInfo(AssociationEnum.HasMany, desc, targetDesc); info.ChildCol = new ColumnDefinition("blog_id", false, true, true, false, OleDbType.Numeric); ActiveRecordPropertyRelationDescriptor propDesc = relService.Build(info); Assert.IsNotNull(propDesc); Assert.IsNotNull(propDesc as ActiveRecordHasManyDescriptor); Assert.AreEqual("Posts", propDesc.PropertyName); Assert.AreEqual(targetDesc, propDesc.TargetType); Assert.AreEqual("blog_id", propDesc.ColumnName); }
private void okButton_Click(object sender, System.EventArgs e) { if (_association == AssociationEnum.Undefined) { cancelButton_Click(sender, e); return; } try { RelationshipInfo info = new RelationshipInfo(_association, _descriptor, SelectedTarget); info.ParentCol = SelectedParentCol; info.ChildCol = SelectedRelatedCol; info.AssociationTable = SelectedAssociationTable; info.Where = where.Text; info.OrderBy = order.Text; info.OuterJoin = outerJoin.Text; // TODO: Add checkbox for proxy info.UseProxy = false; info.Insert = insertButton.Checked; info.Update = updateButton.Checked; info.Lazy = lazyButton.Checked; info.Cascade = cascade.SelectedText; ActiveRecordPropertyRelationDescriptor prop = _relationBuilder.Build(info); _descriptor.PropertiesRelations.Add(prop); } catch (Exception ex) { String message = String.Format("Something is missing... \r\n\r\n{0}", ex.Message); MessageBox.Show(this, message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult = DialogResult.OK; }
public void HasÁndBelongsToMany() { InitKernel(); IRelationshipBuilder relService = ObtainService(); DatabaseDefinition dbdef = new DatabaseDefinition("alias"); TableDefinition compTable = new TableDefinition("companies", dbdef); compTable.AddColumn(new ColumnDefinition("id", true, false, true, false, OleDbType.Integer)); compTable.AddColumn(new ColumnDefinition("name", false, false, false, false, OleDbType.VarChar)); TableDefinition peopleTable = new TableDefinition("people", dbdef); peopleTable.AddColumn(new ColumnDefinition("id", true, false, true, false, OleDbType.Integer)); peopleTable.AddColumn(new ColumnDefinition("name", false, false, false, false, OleDbType.VarChar)); TableDefinition assocTable = new TableDefinition("companiespeople", dbdef); assocTable.AddColumn(new ColumnDefinition("comp_id", true, true, true, false, OleDbType.Integer)); assocTable.AddColumn(new ColumnDefinition("person_id", true, true, false, false, OleDbType.Integer)); ActiveRecordDescriptor desc = new ActiveRecordDescriptor("Company"); ActiveRecordDescriptor targetDesc = new ActiveRecordDescriptor("Person"); RelationshipInfo info = new RelationshipInfo(AssociationEnum.HasAndBelongsToMany, desc, targetDesc); info.AssociationTable = assocTable; info.ParentCol = new ColumnDefinition("comp_id", false, true, false, true, OleDbType.Integer); info.ChildCol = new ColumnDefinition("person_id", false, true, false, true, OleDbType.Integer); ActiveRecordPropertyRelationDescriptor propDesc = relService.Build(info); Assert.IsNotNull(propDesc as ActiveRecordHasAndBelongsToManyDescriptor); Assert.IsNotNull(propDesc); Assert.AreEqual("People", propDesc.PropertyName); Assert.AreEqual(targetDesc, propDesc.TargetType); Assert.AreEqual("person_id", propDesc.ColumnName); Assert.AreEqual("comp_id", (propDesc as ActiveRecordHasAndBelongsToManyDescriptor).ColumnKey); }