Hi Eric:
I am trying to create a strongly typed dataset in .NET 1.1 and am
having a problem with adding relations via the design time XSD editor.
When you generate a relation at runtime, you have the option of
specifying "createConstriants". Normally I would want to have
constraints on a relationship, but I am working on a dataset where I
only need it for navigation. I can't create a relation with the
designer that does not enforce them. Any one know how to do this?
Assume a DataSet with two tables, MainTable and DetailsTable. They have a
PK/FK relationship on UserId which is of type Integer. If we
programatically disable constraints, then this code will succeed:
MainDs ThisDataSet = new MainDs();
MainDs.DetailsTableRow ThisRow =
ThisDataSet.DetailsTable.NewDetailsTableRow();
Debug.Assert(ThisDataSet.MainTable.Constraints.Count == 1, "The Constraint
count in [MainTable] isn't what we expected");
Debug.Assert(ThisDataSet.DetailsTable.Constraints.Count == 1, "The
Constraint count in [DetailsTable] isn't what we expected");
ThisDataSet.EnforceConstraints = false;
ThisRow.UserId = 21;
ThisRow.TodaysDate = DateTime.Now;
ThisDataSet.DetailsTable.Rows.Add(ThisRow);
However if we don't set EnforceConstraints to false, then it will violate
the constraints on the tables and throw an InvalidConstraintException.
Constraints are defined in this case on the tables as opposed to a DataSet.
Unfortunately though, the Constraints collection property only has a get
accessor so it can't be modified directly at the table level. If I
understand the nature of your problem correctly, you can disable the
Constraints on the DataSet and still use the objects therein for navigation,
filtering, sorting, finding etc. When you mention navigation, are you
looking to use a BindingContext/BindingManagerBase to navigate? If so, then
the disabled contraints will pose a problem, but you can get to the same
place (for instance, doing a Master/Details combobox/datagrid) by selecting
the parent record you want, then filtering the child records based on the
parent value, and binding to the filtered child object. Is this essentially
what you're looking for or is there a specific Navigation scenario you need
to address?