DataRelation serializable

DataRelation serializable

System.Data (system.data.dll) class

A DataRelation represents a parent-child relation between two tables. A DataSet stores DataRelation objects in its DataRelationCollection object. These DataRelation objects must be created programmatically, even if they are defined in the data source. ADO.NET data providers automatically determine relationships from the data source.

There are two reasons to add a DataRelation object. The first is make navigation easier. Once you have created the relation, you can use methods such as DataRow.GetChildRows( ) and DataRow.GetParentRow( ) to retrieve related rows. The second reason is to enforce relational constraints. When you create a relation, a corresponding ForeignKeyConstraint is generated by default and added to the table. As long as DataSet.EnforceConstraints is set to true , an exception is thrown when you attempt to perform an action that violates the relationship (such as adding a child that refers to a nonexistent parent).

The easiest way to create a DataRelation is to use the constructor that requires the relation name , the parent DataColumn , and the child DataColumn . Alternatively, you can relate multiple columns or use an overloaded version that allows you to prevent the creation of the ForeignKeyConstraint .

 public class  DataRelation  {  // Public Constructors  public  DataRelation  (string   relationName   ,       DataColumn[ ]   parentColumns   , DataColumn[ ]   childColumns   );    public  DataRelation  (string   relationName   ,  DataColumn[ ]   parentColumns   ,        DataColumn[ ]   childColumns   , bool   createConstraints   );    public  DataRelation  (string   relationName   , DataColumn   parentColumn   , DataColumn   childColumn   );    public  DataRelation  (string   relationName   , DataColumn   parentColumn   ,       DataColumn   childColumn   , bool   createConstraints   );    public  DataRelation  (string   relationName   , string   parentTableName   , string   childTableName   ,       string[ ]   parentColumnNames   , string[ ]   childColumnNames   , bool   nested   );  // Public Instance Properties  public virtual DataColumn[ ]  ChildColumns  {get; }     public virtual ForeignKeyConstraint  ChildKeyConstraint  {get; }     public virtual DataTable  ChildTable  {get; }     public virtual DataSet  DataSet  {get; }     public PropertyCollection  ExtendedProperties  {get; }     public virtual bool  Nested  {set; get; }     public virtual DataColumn[ ]  ParentColumns  {get; }     public virtual UniqueConstraint  ParentKeyConstraint  {get; }     public virtual DataTable  ParentTable  {get; }     public virtual string  RelationName  {set; get; }  // Public Instance Methods  public override string  ToString  (  );  // overrides object   // Protected Instance Methods  protected void  CheckStateForProperty  (  );      protected internal void  OnPropertyChanging  (System.ComponentModel.PropertyChangedEventArgs   pcevent   );    protected internal void  RaisePropertyChanging  ( string   name   );  } 

Returned By

DataRelationCollection.{Add( ) , this}

Passed To

Multiple types



ADO. NET in a Nutshell
ADO.NET in a Nutshell
ISBN: 0596003617
EAN: 2147483647
Year: 2005
Pages: 415

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net