From f69dd1c91def454efd2aecc627dd0140792bb8b1 Mon Sep 17 00:00:00 2001 From: Toby Wicks Date: Sun, 29 Jun 2014 19:57:06 +0930 Subject: [PATCH] Supports return TOP records from ObjectsList(). Closes #92. --- Database/Database.cs | 38 ++++++++++++++++++++++++++++++++++++- Database/DatabaseObjects.cs | 34 ++++++++++++++++++++++++++++++++- Generic/DatabaseObjects.cs | 34 ++++++++++++++++++++++++++++++++- 3 files changed, 103 insertions(+), 3 deletions(-) diff --git a/Database/Database.cs b/Database/Database.cs index 11bec84..023e59d 100644 --- a/Database/Database.cs +++ b/Database/Database.cs @@ -846,7 +846,7 @@ public void ObjectsDeleteAll(IDatabaseObjects objCollection) using (ConnectionScope objConnection = new ConnectionScope(this)) objConnection.ExecuteNonQuery(objDelete); } - + /// -------------------------------------------------------------------------------- /// /// Returns an IList object containing all of the collection's associated child @@ -873,11 +873,47 @@ public void ObjectsDeleteAll(IDatabaseObjects objCollection) /// -------------------------------------------------------------------------------- /// public IList ObjectsList(IDatabaseObjects objCollection) + { + return ObjectsList(objCollection, maxRecords: 0); + } + + /// -------------------------------------------------------------------------------- + /// + /// 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. + /// + /// + /// + /// The collection which contains the objects to load. + /// + /// + /// + /// The maximum number of records to return. + /// Zero returns all of the records. + /// + /// + /// (System.Collections.IList) + /// + /// + /// + /// '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 + /// + /// + /// -------------------------------------------------------------------------------- + /// + 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(); diff --git a/Database/DatabaseObjects.cs b/Database/DatabaseObjects.cs index 8140454..4a14e42 100644 --- a/Database/DatabaseObjects.cs +++ b/Database/DatabaseObjects.cs @@ -486,7 +486,39 @@ protected IDatabaseObject ObjectFromFieldValues(SQL.SQLFieldValues objFieldValue { return Database.ObjectFromFieldValues(this, objFieldValues); } - + + /// -------------------------------------------------------------------------------- + /// + /// 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. + /// + /// + /// + /// The maximum number of records to return. + /// Zero returns all of the records. + /// + /// + /// (System.Collections.IList) + /// + /// + /// + /// '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 + /// + /// + /// -------------------------------------------------------------------------------- + /// + protected IList ObjectsList(int maxRecords) + { + return this.ParentDatabase.ObjectsList(this, maxRecords); + } + /// -------------------------------------------------------------------------------- /// /// Returns an IList object containing all of this collection's objects. This diff --git a/Generic/DatabaseObjects.cs b/Generic/DatabaseObjects.cs index 83d4a96..78e93e8 100644 --- a/Generic/DatabaseObjects.cs +++ b/Generic/DatabaseObjects.cs @@ -341,7 +341,39 @@ protected new T[] ObjectsArray() return objArray; } - + + /// -------------------------------------------------------------------------------- + /// + /// 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. + /// + /// + /// + /// The maximum number of records to return. + /// Zero returns all of the records. + /// + /// + /// (System.Collections.IList) + /// + /// + /// + /// '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 + /// + /// + /// -------------------------------------------------------------------------------- + /// + protected new IList ObjectsList(int maxRecords) + { + return this.ObjectsListConvert(base.ObjectsList(maxRecords)); + } + /// -------------------------------------------------------------------------------- /// /// Returns an IList object containing all of this collection's objects. This