Skip to content

Commit

Permalink
Supports return TOP records from ObjectsList(). Closes #92.
Browse files Browse the repository at this point in the history
  • Loading branch information
hisystems committed Jun 29, 2014
1 parent 03251d5 commit f69dd1c
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 3 deletions.
38 changes: 37 additions & 1 deletion Database/Database.cs
Expand Up @@ -846,7 +846,7 @@ public void ObjectsDeleteAll(IDatabaseObjects objCollection)
using (ConnectionScope objConnection = new ConnectionScope(this))
objConnection.ExecuteNonQuery(objDelete);
}

/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an IList object containing all of the collection's associated child
Expand All @@ -873,11 +873,47 @@ public void ObjectsDeleteAll(IDatabaseObjects objCollection)
/// --------------------------------------------------------------------------------
///
public IList ObjectsList(IDatabaseObjects objCollection)
{
return ObjectsList(objCollection, maxRecords: 0);
}

/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an IList object containing the first n of the collection's associated child
/// objects. This function is useful when loading a set of objects for a subset or
/// for use with the IEnumerable interface.
/// </summary>
///
/// <param name="objCollection">
/// The collection which contains the objects to load.
/// </param>
///
/// <param name="maxRecords">
/// The maximum number of records to return.
/// Zero returns all of the records.
/// </param>
///
/// <returns><see cref="Collections.IList" /> (System.Collections.IList)</returns>
///
/// <example>
/// <code>
/// 'Can be used to provide an enumerator for use with the "For Each" clause
/// Private Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
///
/// Return objDatabase.ObjectsList(objGlobalProductsInstance, 1000).GetEnumerator
///
/// End Function
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
public IList ObjectsList(IDatabaseObjects objCollection, int maxRecords)
{
IList objArrayList = new ArrayList();
SQL.SQLSelect objSelect = new SQL.SQLSelect();

SQL.SQLSelectTable objPrimaryTable = objSelect.Tables.Add(objCollection.TableName());
objSelect.Top = maxRecords;
objSelect.Tables.Joins = objCollection.TableJoins(objPrimaryTable, objSelect.Tables);
objSelect.Where = objCollection.Subset();
objSelect.OrderBy = objCollection.OrderBy();
Expand Down
34 changes: 33 additions & 1 deletion Database/DatabaseObjects.cs
Expand Up @@ -486,7 +486,39 @@ protected IDatabaseObject ObjectFromFieldValues(SQL.SQLFieldValues objFieldValue
{
return Database.ObjectFromFieldValues(this, objFieldValues);
}


/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an IList object containing the first n of the collection's associated child
/// objects. This function is useful when loading a set of objects for a subset or
/// for use with the IEnumerable interface.
/// </summary>
///
/// <param name="maxRecords">
/// The maximum number of records to return.
/// Zero returns all of the records.
/// </param>
///
/// <returns><see cref="Collections.IList" /> (System.Collections.IList)</returns>
///
/// <example>
/// <code>
/// 'Alternatively, the DatabaseObjectsEnumerable class can be used which
/// 'automatically incorporates an enumerator
/// Private Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
///
/// Return MyBase.ObjectsList(1000).GetEnumerator
///
/// End Function
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
protected IList ObjectsList(int maxRecords)
{
return this.ParentDatabase.ObjectsList(this, maxRecords);
}

/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an IList object containing all of this collection's objects. This
Expand Down
34 changes: 33 additions & 1 deletion Generic/DatabaseObjects.cs
Expand Up @@ -341,7 +341,39 @@ protected new T[] ObjectsArray()

return objArray;
}


/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an IList object containing the first n of the collection's associated child
/// objects. This function is useful when loading a set of objects for a subset or
/// for use with the IEnumerable interface.
/// </summary>
///
/// <param name="maxRecords">
/// The maximum number of records to return.
/// Zero returns all of the records.
/// </param>
///
/// <returns><see cref="Collections.IList" /> (System.Collections.IList)</returns>
///
/// <example>
/// <code>
/// 'Alternatively, the DatabaseObjectsEnumerable class can be used which
/// 'automatically incorporates an enumerator
/// Private Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
///
/// Return MyBase.ObjectsList(1000).GetEnumerator
///
/// End Function
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
protected new IList<T> ObjectsList(int maxRecords)
{
return this.ObjectsListConvert(base.ObjectsList(maxRecords));
}

/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an IList object containing all of this collection's objects. This
Expand Down

0 comments on commit f69dd1c

Please sign in to comment.