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

irwsoft.com


Home
IRWDataObject's code to select and sorting record(s) from table(s)

How easy to sorting your data-view design with IRWDataObject.

string sqlConnectionString = "...";

// define view-schema for Student class
ViewSchema vs = new ViewSchema(typeof(Student), null);

// select records with criteria ClassID
// define where-schema for fields Name with default value

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

// order records by column Name
// define order-schema for fields Name with descending order

OrderBySchema os = new OrderBySchema(vs); os.Add(typeof(Student), typeof(Student), "Name", SqlSorting.Descending);

// 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");
}

Copyright by : IrwSoft © 2009 , All Rights Reserved