Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / System / data / design / DesignRelationCollection.cs / 1 / DesignRelationCollection.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Information Contained Herein is Proprietary and Confidential.
//
//-----------------------------------------------------------------------------
namespace System.Data.Design{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
///
///
internal class DesignRelationCollection: DataSourceCollectionBase {
private DesignDataSource dataSource;
public DesignRelationCollection(DesignDataSource dataSource) : base(dataSource) {
this.dataSource = dataSource;
}
private DataSet DataSet{
get{
if (dataSource != null){
return dataSource.DataSet;
}
return null;
}
}
protected override Type ItemType {
get {
return typeof(DesignRelation);
}
}
protected override INameService NameService {
get {
return DataSetNameService.DefaultInstance;
}
}
internal DesignRelation this[ForeignKeyConstraint constraint] {
get {
if (constraint == null) {
return null;
}
foreach (DesignRelation relation in this) {
if (relation.ForeignKeyConstraint == constraint) {
return relation;
}
}
return null;
}
}
internal DesignRelation this[string name] {
get {
return (DesignRelation) FindObject(name);
}
}
public void Remove( DesignRelation rel ) {
List.Remove( rel );
}
public int Add( DesignRelation rel ) {
return List.Add( rel );
}
public bool Contains( DesignRelation rel ) {
return List.Contains( rel );
}
///
/// Note: this function need to call base first
/// to ensure the undo model work!
///
protected override void OnInsert( int index, object value ) {
ValidateType( value );
DesignRelation designRelation = (DesignRelation)value;
if( (this.dataSource != null) && (designRelation.Owner == this.dataSource) ) {
Debug.Fail( "Relation already belongs to this DataSource" );
return; // no-op
}
if( (this.dataSource != null) && (designRelation.Owner != null) ) {
throw new InternalException( VSDExceptions.DataSource.RELATION_BELONGS_TO_OTHER_DATA_SOURCE_MSG,
VSDExceptions.DataSource.RELATION_BELONGS_TO_OTHER_DATA_SOURCE_CODE );
}
if (designRelation.Name == null || designRelation.Name.Length == 0) {
designRelation.Name = CreateUniqueName(designRelation);
}
ValidateName(designRelation);
DataSet dataSet = DataSet;
if (dataSet != null) {
if (designRelation.ForeignKeyConstraint != null) {
ForeignKeyConstraint constraint = designRelation.ForeignKeyConstraint;
if (constraint.Columns.Length > 0) {
DataTable dataTable = constraint.Columns[0].Table;
if (dataTable != null && !dataTable.Constraints.Contains(constraint.ConstraintName)) {
dataTable.Constraints.Add(constraint);
}
}
}
if (designRelation.DataRelation != null &&
(!dataSet.Relations.Contains(designRelation.DataRelation.RelationName))){
dataSet.Relations.Add(designRelation.DataRelation);
}
}
// we should insert to the collection later than we insert to DataSet
// the reason is the DataSet will create a keyConstraint for relation, we want the constraint undo unit to be added before
// our relation undo unit... otherwise, the undo/redo will fail, as DataSet will create another constraint for us..
base.OnInsert( index, value );
designRelation.Owner = dataSource;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ReverseQueryOperator.cs
- QueueTransferProtocol.cs
- TextWriterTraceListener.cs
- RoutedUICommand.cs
- RegexMatch.cs
- AcceleratedTokenProviderState.cs
- GenerateScriptTypeAttribute.cs
- SimpleLine.cs
- TextBlockAutomationPeer.cs
- BehaviorEditorPart.cs
- NumericUpDownAcceleration.cs
- HtmlInputImage.cs
- IisTraceListener.cs
- PartialCachingControl.cs
- QilPatternVisitor.cs
- ExtractCollection.cs
- ExceptionAggregator.cs
- MissingMemberException.cs
- TableProvider.cs
- PreloadHost.cs
- WhitespaceRule.cs
- HtmlLink.cs
- SspiWrapper.cs
- DataTableReader.cs
- Range.cs
- DbConnectionOptions.cs
- CompatibleIComparer.cs
- ChannelDemuxer.cs
- XPathSingletonIterator.cs
- WindowsSecurityToken.cs
- TypefaceCollection.cs
- ConfigurationManagerInternalFactory.cs
- SelectionChangedEventArgs.cs
- PenCursorManager.cs
- DataFieldConverter.cs
- Listbox.cs
- TypeConverterHelper.cs
- AuthenticationModulesSection.cs
- Error.cs
- NullableDoubleSumAggregationOperator.cs
- Binding.cs
- Pair.cs
- LoginView.cs
- AutomationPeer.cs
- DefaultPrintController.cs
- IPipelineRuntime.cs
- SessionStateSection.cs
- MsmqChannelFactoryBase.cs
- XsltException.cs
- XmlSchemaElement.cs
- InputGestureCollection.cs
- CheckedListBox.cs
- RegisteredScript.cs
- SamlSerializer.cs
- TextModifier.cs
- ValueSerializer.cs
- DelayedRegex.cs
- ToggleButton.cs
- OleDbRowUpdatedEvent.cs
- LoginName.cs
- FieldAccessException.cs
- CaseStatement.cs
- FreeFormDesigner.cs
- ReferentialConstraint.cs
- TimelineGroup.cs
- RtfToXamlLexer.cs
- LoadGrammarCompletedEventArgs.cs
- DataFieldCollectionEditor.cs
- ModuleConfigurationInfo.cs
- NetworkInformationException.cs
- GridViewColumnCollectionChangedEventArgs.cs
- MachineSettingsSection.cs
- TemplatePartAttribute.cs
- __FastResourceComparer.cs
- TextServicesCompartment.cs
- FileNotFoundException.cs
- DesignerEventService.cs
- ArraySortHelper.cs
- StaticDataManager.cs
- VisualStyleElement.cs
- EdmTypeAttribute.cs
- oledbconnectionstring.cs
- DecoderReplacementFallback.cs
- RegexWorker.cs
- InvalidOleVariantTypeException.cs
- SharedDp.cs
- Renderer.cs
- Route.cs
- ExportException.cs
- WebPartManager.cs
- MetadataItemEmitter.cs
- CompiledXpathExpr.cs
- ElementMarkupObject.cs
- TemplateBindingExtension.cs
- PeerNodeAddress.cs
- ConfigurationManagerInternalFactory.cs
- ColorBlend.cs
- ExpressionServices.cs
- GridViewDeleteEventArgs.cs
- ColorInterpolationModeValidation.cs