Irwsoft Data Framework

Table Data-schema
Brief Information
EditionsAll Editions
TopicsTable data-schema class.

This sample will show how to design dataschema class for a table in database.

What you will learn :

  1. Irwsoft.Data.TableAttribute marks a class as table data-schema.

  2. Irwsoft.Data.Column and Irwsoft.Data.ColumnAttribute :

    • Irwsoft.Data.Column represents as a column of the table or table-function.
    • Irwsoft.Data.ColumnAttribute used to marks a field as a column of the table or table-function data-schema.

Example : We have Person table with structure like this :

  • PersonID (int, PK)
  • FirstName (string)
  • DateOfBirth (Date)
  • Status (boolean) - represents available status of a person.
  • LeaderID (int, FK) - relate to PersonID as a relation of a manager and his/her members.
  • CountryID (int, FK) - relate to CountryID of Country table.
C# code
// 1) Must using TableAttribute to describe class table
public class PersonTable
     // 2) Must declare all columns needed with private modifier and ColumnAttribute on it.
     //    NOTE : For read-only column set ReadOnly to true and string column should specify its size.

     [Column("PersonId"DbType.Int32, true, PrimaryKey = true)]
     private Column _personId;

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

     [Column("DateOfBirth"DbType.DateTime, false)]
     private Column _dateOfBirth;

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

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

     [Column("CountryId"DbType.Int32, false)]
     private Column _countryId;

     // 3) 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 Column PersonId { get { return _personId; } }
     public Column FirstName { get { return _firstName; } }
     // ... other properties here

     // 4) 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.