Irwsoft Data Framework

Relation Data-schema
Brief Information
EditionsAll Editions
TopicsRetrieve records from Master table or Child table of a dataschema.
RemarksA dataschema class can have relations to another dataschema as a master-table or a child-table.

The idea behind relation data-schema is that if you want to get data that related to a specific record. You don't need to retrieve it separately, but retrieve it directly from a field of the main dataschema. The relation field has Irwsoft.Data.RelationAttribute and will return Irwsoft.Data.Table<T> type, which T is dataschema class of master-table or child-table.

This sample will show how to design dataschema class for relation tables using Irwsoft Data Framework.

Example : Person table that have LeaderId foreign-key-column that can be related to PersonId primary-key-column.

C# code
public class PersonTable
     [Column("PersonId"DbType.Int32, true, PrimaryKey = true)]
     private Column _personId;

     [Column("FirstName"DbType.String, false)]
     private Column _firstName;

     [Column("LeaderId"DbType.Int32, false)]
     private Column _leaderId;

     [Column("Status"DbType.Boolean, false)]
     private Column _status;

     // 1) Declare all relation tables needed with private modifier and RelationAttribute on it.
     //    NOTE : You must specify type of dataschema objects for both primary and foreign,
     //           column-name that make relation, and
     //           status of relation table as primary or foreign.

     [Relation("Leader"typeof(PersonTable), typeof(PersonTable), new string[] { "PersonId" },
     new string[] { "LeaderId" }, Irwsoft.Data.TableStatus.PrimaryOrUniqueTable, ProviderName.SqlClient)]
     private Table<PersonTable> _leader;

     [Relation("Members"typeof(PersonTable), typeof(PersonTable), new string[] { "PersonId" },
     new string[] { "LeaderId" }, Irwsoft.Data.TableStatus.ForeignTable, ProviderName.SqlClient)]
     private Table<PersonTable> _members;

     // 2) Declare public get accessor to read the data.
     //    NOTE : you must not provide set/write accessor since it will initialized by calling
     //           Irwsoft.Data.DataFactories.InitTableSchema

     public Table<PersonTable> Leader { get { return _leader; } }

     public Table<PersonTable> Members { get { return _members; } }

     // ... other properties here

     // 3) Must have parameterless constructors, that call Irwsoft.Data.DataFactories.InitTableSchema

     public PersonTable()

Related Topics :

Irwsoft Data Ultimate Edition provides comprehensive features of Irwsoft Data Framework and support from irwsoft.