protected virtual void OnReadDataSet(ReadDataSetEventArgs e)
 {
     if (ReadDataSet != null)
     {
         ReadDataSet(this, e);
     }
 }
        /// <summary>
        /// Create a DataList from a dataset
        /// </summary>
        /// <param name="logonId">Logon id</param>
        /// <param name="queryName">Name given to the data set</param>
        /// <param name="queryCriteria">The criteria used to create the dataset.
        /// If there are mutiple critera parameters they should be concatenated into
        /// one string.
        /// This can be empty if the dataset will always be created by an identical query
        /// or if the criteria has been added on to the end of the query name to
        /// make the cache available for longer.</param>
        /// <param name="collectionRequest">Information about the collection being requested</param>
        /// <param name="mappings">Mappings to map each dataset field to the data list
        /// entity property name</param>
        /// <returns></returns>
        public DataList <T> Create(Guid logonId, string queryName, string queryCriteria,
                                   CollectionRequest collectionRequest,
                                   ImportMapping[] mappings)
        {
            if (queryName == null || queryName.Trim() == string.Empty)
            {
                throw new Exception("QueryName must be specified");
            }

            if (collectionRequest == null)
            {
                throw new Exception("CollectionRequest must be specified");
            }

            if (collectionRequest.StartRow < 0)
            {
                throw new Exception("StartRow must be zero or greater");
            }

            DataSet dataSet = null;

            DataSetsCache dataSetsCache = null;

            if (Host.DataSetCachingOn)
            {
                // Get the datasets cache for the logged on user
                dataSetsCache = Host.GetDataSetsCache(logonId);

                //if we move from a higher page to page 1 then the start row will be 0
                //we do not require to get a new dataset at this time
                //if (collectionRequest.StartRow > 0 && !collectionRequest.ForceRefresh)

                if (!collectionRequest.ForceRefresh)
                {
                    // The start row is greater than zero and not forcing refresh
                    // so try to get a cached dataset.
                    dataSet = dataSetsCache.Retreive(queryName, queryCriteria);
                }
            }

            if (dataSet == null)
            {
                // Create a new dataset
                ReadDataSetEventArgs args = new ReadDataSetEventArgs();

                // Call the event to read the dataset
                OnReadDataSet(args);

                dataSet = args.DataSet;

                if (dataSet == null)
                {
                    throw new Exception("No data set has been created");
                }

                if (Host.DataSetCachingOn)
                {
                    // Add the dataset to the cache
                    dataSetsCache.Add(dataSet, queryName, queryCriteria);
                }
            }

            // Assume there is only one table in the dataset.
            // This may need to be enhanced later.
            if (dataSet.Tables.Count != 1)
            {
                throw new Exception("Database query did not return 1 table");
            }

            DataTable table = dataSet.Tables[0];

            DataList <T> dataList = new DataList <T>();

            dataList.FirstRowNumber = collectionRequest.StartRow;
            dataList.TotalRowCount  = table.Rows.Count;

            // Copy the rows from the dataset to the data list
            ImportData(dataList, mappings, table,
                       collectionRequest.StartRow, collectionRequest.RowCount);

            return(dataList);
        }