本文整理汇总了C#中System.Data.DataRelation.SetChildKeyConstraint方法的典型用法代码示例。如果您正苦于以下问题:C# DataRelation.SetChildKeyConstraint方法的具体用法?C# DataRelation.SetChildKeyConstraint怎么用?C# DataRelation.SetChildKeyConstraint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataRelation
的用法示例。
在下文中一共展示了DataRelation.SetChildKeyConstraint方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveCore
protected override void RemoveCore(DataRelation relation) {
base.RemoveCore(relation);
dataSet.OnRemoveRelationHack(relation);
relation.SetDataSet(null);
relation.ChildKey.GetSortIndex().RemoveRef();
if (relation.Nested) {
relation.ChildTable.CacheNestedParent();
}
for (int i = 0; i < relations.Count; i++) {
if (relation == relations[i]) {
relations.RemoveAt(i);
((DataRelationCollection.DataTableRelationCollection)(relation.ParentTable.ChildRelations)).Remove(relation); // Remove Cache from ParentTable -> ChildRelations
((DataRelationCollection.DataTableRelationCollection)(relation.ChildTable.ParentRelations)).Remove(relation); // Removing Cache from ChildTable -> ParentRelations
if (relation.Nested)
relation.ChildTable.CacheNestedParent();
UnregisterName(relation.RelationName);
relation.SetParentKeyConstraint(null);
relation.SetChildKeyConstraint(null);
return;
}
}
throw ExceptionBuilder.RelationDoesNotExist();
}
示例2: AddCore
protected override void AddCore(DataRelation relation) {
base.AddCore(relation);
if (relation.ChildTable.DataSet != dataSet || relation.ParentTable.DataSet != dataSet)
throw ExceptionBuilder.ForeignRelation();
relation.CheckState();
if(relation.Nested) {
relation.CheckNestedRelations();
}
if (relation.relationName.Length == 0)
relation.relationName = AssignName();
else
RegisterName(relation.relationName);
DataKey childKey = relation.ChildKey;
for (int i = 0; i < relations.Count; i++) {
if (childKey.ColumnsEqual(((DataRelation)relations[i]).ChildKey)) {
if (relation.ParentKey.ColumnsEqual(((DataRelation)relations[i]).ParentKey))
throw ExceptionBuilder.RelationAlreadyExists();
}
}
relations.Add(relation);
((DataRelationCollection.DataTableRelationCollection)(relation.ParentTable.ChildRelations)).Add(relation); // Caching in ParentTable -> ChildRelations
((DataRelationCollection.DataTableRelationCollection)(relation.ChildTable.ParentRelations)).Add(relation); // Caching in ChildTable -> ParentRelations
relation.SetDataSet(dataSet);
relation.ChildKey.GetSortIndex().AddRef();
if (relation.Nested) {
relation.ChildTable.CacheNestedParent();
}
ForeignKeyConstraint foreignKey = relation.ChildTable.Constraints.FindForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference);
if (relation.createConstraints) {
if (foreignKey == null) {
relation.ChildTable.Constraints.Add(foreignKey = new ForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference));
// try to name the fk constraint the same as the parent relation:
try {
foreignKey.ConstraintName = relation.RelationName;
}
catch (Exception e) {
//
if (!Common.ADP.IsCatchableExceptionType(e)) {
throw;
}
ExceptionBuilder.TraceExceptionWithoutRethrow(e);
// ignore the exception
}
}
}
UniqueConstraint key = relation.ParentTable.Constraints.FindKeyConstraint(relation.ParentColumnsReference);
relation.SetParentKeyConstraint(key);
relation.SetChildKeyConstraint(foreignKey);
}
示例3: ProcessReferenceKey
private void ProcessReferenceKey (XmlSchemaElement element, XmlSchemaKeyref keyref)
{
// Basic concept came from XmlSchemaMapper.cs
string tableName = GetSelectorTarget (keyref.Selector.XPath);
DataColumn [] cols;
DataTable dt = dataset.Tables [tableName];
if (dt == null)
throw new DataException (String.Format ("Invalid XPath selection inside selector. Cannot find: {0}", tableName));
cols = new DataColumn [keyref.Fields.Count];
int i = 0;
foreach (XmlSchemaXPath Field in keyref.Fields) {
string colName = Field.XPath;
bool isAttr = colName.Length > 0 && colName [0] == '@';
int index = colName.LastIndexOf (':');
if (index > 0)
colName = colName.Substring (index + 1);
else if (isAttr)
colName = colName.Substring (1);
colName = XmlConvert.DecodeName (colName);
DataColumn col = dt.Columns [colName];
if (isAttr && col.ColumnMapping != MappingType.Attribute)
throw new DataException ("The XPath specified attribute field, but mapping type is not attribute.");
if (!isAttr && col.ColumnMapping != MappingType.Element)
throw new DataException ("The XPath specified simple element field, but mapping type is not simple element.");
cols [i] = col;
i++;
}
string name = keyref.Refer.Name;
// get the unique constraint for the releation
UniqueConstraint uniq = FindConstraint (name, element);
// generate the FK.
ForeignKeyConstraint fkc = new ForeignKeyConstraint(keyref.Name, uniq.Columns, cols);
dt.Constraints.Add (fkc);
// generate the relation.
DataRelation rel = new DataRelation (keyref.Name, uniq.Columns, cols, false);
if (keyref.UnhandledAttributes != null) {
foreach (XmlAttribute attr in keyref.UnhandledAttributes)
if (attr.LocalName == "IsNested" && attr.Value == "true" && attr.NamespaceURI == XmlConstants.MsdataNamespace)
rel.Nested = true;
}
rel.SetParentKeyConstraint (uniq);
rel.SetChildKeyConstraint (fkc);
dataset.Relations.Add (rel);
}
示例4: RemoveCore
protected override void RemoveCore (DataRelation relation)
{
base.RemoveCore (relation);
relation.SetDataSet (null);
relation.ParentTable.ChildRelations.Remove (relation);
relation.ChildTable.ParentRelations.Remove (relation);
relation.SetParentKeyConstraint (null);
relation.SetChildKeyConstraint (null);
}
示例5: ProcessRelationIdentity
private void ProcessRelationIdentity (XmlSchemaElement element, ConstraintStructure c)
{
// Basic concept came from XmlSchemaMapper.cs
string tableName = c.TableName;
DataColumn [] cols;
DataTable dt = dataset.Tables [tableName];
if (dt == null)
throw new DataException (String.Format ("Invalid XPath selection inside selector. Cannot find: {0}", tableName));
cols = new DataColumn [c.Columns.Length];
for (int i = 0; i < cols.Length; i++) {
string colName = c.Columns [i];
bool isAttr = c.IsAttribute [i];
DataColumn col = dt.Columns [colName];
if (isAttr && col.ColumnMapping != MappingType.Attribute)
throw new DataException ("The XPath specified attribute field, but mapping type is not attribute.");
if (!isAttr && col.ColumnMapping != MappingType.Element)
throw new DataException ("The XPath specified simple element field, but mapping type is not simple element.");
cols [i] = col;
}
string name = c.ReferName;
// get the unique constraint for the releation
UniqueConstraint uniq = FindConstraint (name, element);
// generate the FK.
ForeignKeyConstraint fkc = new ForeignKeyConstraint(c.ConstraintName, uniq.Columns, cols);
dt.Constraints.Add (fkc);
if (!c.IsConstraintOnly) {
// generate the relation.
DataRelation rel = new DataRelation (c.ConstraintName, uniq.Columns, cols, true);
rel.Nested = c.IsNested;
rel.SetParentKeyConstraint (uniq);
rel.SetChildKeyConstraint (fkc);
dataset.Relations.Add (rel);
}
}
示例6: AddCore
protected override void AddCore(DataRelation relation)
{
base.AddCore(relation);
if ((relation.ChildTable.DataSet != this.dataSet) || (relation.ParentTable.DataSet != this.dataSet))
{
throw ExceptionBuilder.ForeignRelation();
}
relation.CheckState();
if (relation.Nested)
{
relation.CheckNestedRelations();
}
if (relation.relationName.Length == 0)
{
relation.relationName = base.AssignName();
}
else
{
base.RegisterName(relation.relationName);
}
DataKey childKey = relation.ChildKey;
for (int i = 0; i < this.relations.Count; i++)
{
if (childKey.ColumnsEqual(((DataRelation) this.relations[i]).ChildKey) && relation.ParentKey.ColumnsEqual(((DataRelation) this.relations[i]).ParentKey))
{
throw ExceptionBuilder.RelationAlreadyExists();
}
}
this.relations.Add(relation);
((DataRelationCollection.DataTableRelationCollection) relation.ParentTable.ChildRelations).Add(relation);
((DataRelationCollection.DataTableRelationCollection) relation.ChildTable.ParentRelations).Add(relation);
relation.SetDataSet(this.dataSet);
relation.ChildKey.GetSortIndex().AddRef();
if (relation.Nested)
{
relation.ChildTable.CacheNestedParent();
}
ForeignKeyConstraint constraint = relation.ChildTable.Constraints.FindForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference);
if (relation.createConstraints && (constraint == null))
{
relation.ChildTable.Constraints.Add(constraint = new ForeignKeyConstraint(relation.ParentColumnsReference, relation.ChildColumnsReference));
try
{
constraint.ConstraintName = relation.RelationName;
}
catch (Exception exception)
{
if (!ADP.IsCatchableExceptionType(exception))
{
throw;
}
ExceptionBuilder.TraceExceptionWithoutRethrow(exception);
}
}
UniqueConstraint constraint2 = relation.ParentTable.Constraints.FindKeyConstraint(relation.ParentColumnsReference);
relation.SetParentKeyConstraint(constraint2);
relation.SetChildKeyConstraint(constraint);
}