Irwsoft Data Framework

Apply
Brief Information
EditionsUltimate
ProvidersSqlClient.
DataschemaTable-Function.
TopicsUsing Apply syntax.
RemarksThe APPLY operator is similar to the JOIN operator, but the difference is that the right-hand side operator of APPLY can reference columns from the left-hand side.
This usually used by table-function which parameter taken from column of table in the left-hand side.

Irwsoft Data Framework supports two apply syntax :

  • Cross Apply ,
  • Outer Apply

These apply syntax works like join syntax but with different proccess. With this syntax the right table will be proccessed for each record of left table, this is possible in the case of the right table is table function that need data from the record in left table. In join terms cross apply is inner join, meanwhile outer apply is left outer join.

NOTE :

  • Ultimate Edition feature only.
  • Available for SqlClient provider only.

Example :

display all records of Person table that have leader, but this time it use table function Dbo.GetPpersonTable(@PersonID)
SELECT * FROM PERSON P1 CROSS APPLY DBO.GETPERSONTABLE(P1.LEADERID)

C# code
// Declare and initiate a new instance PersonTable that represent as member data
PersonTable member = new PersonTable();

// Declare and initiate a new instance GetPersonTable that represent as leader data
// NOTE : this is a table function schema.

GetPersonTable leader = new GetPersonTable();

SqlSelectFrom select = new SqlSelectFrom(member);
// Don’t forget to set connection string !
// NOTE : it is optional if the data-schema class using default connection.

select.ConnectionString = "...";  // [OPTIONAL]

// to display person with his/her leader data,
// we will use CROSS APPLY between member.LeaderId and leader.PersonId
// set the parameter of GetPersonTable with LeaderId of member.

leader.ParamPersonId.Value = member.LeaderId;
// set CROSS APPLY to GetPersonTable function.
select.Tables.CrossApply(leader);

// Execute the query
Irwsoft.Data.DataView dv = select.Execute();

// here how to access data from DataView by define which column to read the data
String firstNamePerson = dv.Rows[0][person.FirstName].ToString();
String firstNameLeader = dv.Rows[0][leader.FirstName].ToString();
Irwsoft Data Ultimate Edition provides all enhanced features of Irwsoft Data Framework and support from irwsoft.