LoadCollection
The LoadCollection method uses the LoadCollection method of an IDO to query either an IDO collection or a database table and return the results to the user.
Example 1 – Basic load collection
This example code retrieves the user ID, name, and description from the Users table.
Client client = new Client( requestServiceURL, IDOProtocol.Http );
LoadCollectionResponseData response = default( LoadCollectionResponseData );
using ( client )
{
LoadCollectionRequestData request = new LoadCollectionRequestData()
{
IDOName = "UserNames",
PropertyList = new PropertyList( "UserId, Username, UserDesc" ),
RecordCap = -1
};
response = client.LoadCollection( request );
// Property info can be enumerated as follows
foreach ( IDOItem item in response.Items )
{
// Do something...
foreach ( IDOPropertyValue property in item.PropertyValues )
{
Console.WriteLine( property.Value );
}
}
}
Example 2 – Custom load collection
This example code retrieves the note content and description from the Object Notes table using the custom load method GetNotesSp.
Client client = new Client( requestServiceURL, IDOProtocol.Http );
LoadCollectionResponseData response = default( LoadCollectionResponseData );
using ( client )
{
InvokeParameterList clmParameters = new InvokeParameterList
{
"UserNames",
"4d6cb1eb-e4fc-4e12-aae8-95ff1086ee8c"
};
CustomLoadMethod clm = new CustomLoadMethod
{
Name = "GetNotesSp",
Parameters = clmParameters
};
LoadCollectionRequestData request = new LoadCollectionRequestData()
{
IDOName = "ObjectNotes",
PropertyList = new PropertyList( "SpcnNoteContent, SpcnNoteDesc" ),
RecordCap = -1,
CustomLoadMethod = clm
};
response = client.LoadCollection( request );
// Property info can be enumerated as follows
foreach ( IDOItem item in response.Items )
{
// Do something...
foreach ( IDOPropertyValue property in item.PropertyValues )
{
Console.WriteLine( property.Value );
}
}
}
Example 3 – Nested load collection
This example code is for a nested or hierarchical request. This request queries the Users table and the User Emails tables in a single request, to get the usernames and associated email addresses for each user.
Client client = new Client( requestServiceURL, IDOProtocol.Http );
LoadCollectionResponseData response = default( LoadCollectionResponseData );
using ( client )
{
LoadCollectionRequestData emailsRequest = new LoadCollectionRequestData
{
IDOName = "UserEmails",
PropertyList = new PropertyList( "EmailAddress, EmailType" ),
RecordCap = -1
};
// Set the relationship data of the child and parent IDOs
emailsRequest.SetLinkBy( "UserId", "UserId" );
LoadCollectionRequestData usersRequest = new LoadCollectionRequestData
{
IDOName = "UserNames",
PropertyList = new PropertyList( "UserId, Username, UserDesc" ),
RecordCap = -1
};
// Nest the user emails LoadCollection request inside the user LoadCollection request
usersRequest.AddNestedRequest( emailsRequest );
response = client.LoadCollection( usersRequest );
// Property info can be enumerated as follows
foreach ( IDOItem item in response.Items )
{
// Do something...
foreach ( IDOPropertyValue property in item.PropertyValues )
{
Console.WriteLine( property.Value );
}
}
}