IRWDataObject - .NET Object Relational Mapper
.NET Object Relational Mapper to Database

irwsoft.com


Home
IRWDataObject's code to select records from relational tables/entities between Student & Class

This code show you how easy to build a data-view with your .net language.

string sqlConnectionString = "...";

// define view-schema with Student class as first entity
ViewSchema vs = new ViewSchema(typeof(Student), null);

// define relation to Class with foreign-primary key columns
vs.Add(typeof(Student), SqlRelational.InnerJoin, typeof(Class), typeof(Student), "ClassID", SqlComparison.Equal, typeof(Class), "ID", null);

// select a record with criteria Name
// define where-schema for fields Name with default value is 'Andy'

WhereSchema ws = new WhereSchema(vs); ws.Add(SqlConditional.And, typeof(Student), typeof(Student), "Name", SqlComparison.Equal, "Andy");

// define mapper object
SelectMapper m = new SelectMapper(sqlConnectionString, vs);

// execute view-schema with new Student-object
// return value is ViewResult object

ViewResult result = m.Execute(null);

// display record from ViewResult object
foreach (ViewResultRecordInfo item in result)
{
for (int i = 0; i < vs.Columns.Length; i++)
{
Console.Write(item[vs.Columns[i].TableColumnName, vs.Columns[i].TableEntity].Value.ToString().PadLeft(25)); }
Console.WriteLine("\n");
}


Note : You can even define realtion to a view-schema

Copyright by : IrwSoft © 2009 , All Rights Reserved