I wrote a custom DataSet (based on strongly-typed DataSet, the further I see) and I want to make it suitable to be used on design-time, things like be dragged from ToolBox (generated automatically as a DataSet tool). All of this it's happening 'cause I'm trying to keep the development methodology, set by my workmates (I'm the new one, hahaha), Of course I'm aware of existence of Entity Framework and that kind of things. So, I'm getting this error when I place it on my form:
Relation named 'ParentChild_Relation' already belongs to this DataSet
Of course it's a matter relationship
This is the code:
Public Class MyDataSet
Inherits DataSet
Public Const PARENTCHILD_RELATION As String = "ParentChild_Relation"
Public Sub New()
MyBase.New()
Me.BeginInit()
Me.CreateDataSet()
Me.EndInit()
End Sub
Private Sub CreateDataSet()
DataSetName = "Test"
Me.EnforceConstraints = True
Me.Tables.Add(New ParentTable) 'custom datatable
Me.Tables.Add(New ChildTable) 'custom datatable
CreateRelation()
End Sub
Private Sub CreateRelation()
With DirectCast(Me.Tables(ChildTable.TABLENAME).Constraints.Add(PARENTCHILD_RELATION ,
Me.Tables(ParentTable.TABLENAME).Columns(ParentTable.ID),
Me.Tables(ChildTable.TABLENAME).Columns(ChildTable.ID)), ForeignKeyConstraint)
.UpdateRule = Rule.Cascade
.DeleteRule = Rule.Cascade
Me.Relations.Add(.ConstraintName, .RelatedColumns, .Columns, False)
End With
End Sub
End Class
I'll be aware of any possible help
EDIT
It works without this line:
Me.Relations.Add(.ConstraintName, .RelatedColumns, .Columns, False)
But, I still want the DataSet relation because is the way they work
EDIT 2
Without the previous line, it doesn't find relation through bindings:
BindingSource.DataSource = New MyDataSet
BindingSource.DataMember = "ParentChild_Relation"