public static TMSApplicationDetails Get(System.Int64 adApplicationId)
    {
        DataSet               ds;
        Database              db;
        string                sqlCommand;
        DbCommand             dbCommand;
        TMSApplicationDetails instance;


        instance = new TMSApplicationDetails();

        db         = DatabaseFactory.CreateDatabase();
        sqlCommand = "[dbo].gspTMSApplicationDetails_SELECT";
        dbCommand  = db.GetStoredProcCommand(sqlCommand, adApplicationId);

        // Get results.
        ds = db.ExecuteDataSet(dbCommand);
        // Verification.
        if (ds == null || ds.Tables[0].Rows.Count == 0)
        {
            throw new ApplicationException("Could not get TMSApplicationDetails ID:" + adApplicationId.ToString() + " from Database.");
        }
        // Return results.
        ds.Tables[0].TableName = TABLE_NAME;

        instance.MapFrom(ds.Tables[0].Rows[0]);
        return(instance);
    }
    public static TMSApplicationDetails[] Search(System.Int64?adApplicationId, System.Int64?adSenderId, System.Int64?adReceivedId, System.Int64?adReplyID, System.String adApplicationFor, System.String adSubject, System.String adDescription, System.DateTime?adLeaveFromDate, System.DateTime?adLeaveToDate, System.DateTime?adDate, System.Int32?adStatus, System.Int64?adMinitorID, System.String adSentTo, System.String adExtra1, System.String adExtra2, System.String adCasualLeave, System.String adPaidLeave, System.String adSickLeave, System.String adEarnedLeave, System.String adOtherLeave, System.String adApproveStatus, System.Int64?adApproveByID, System.String adApproveByType, System.DateTime?adApproveDate)
    {
        DataSet   ds;
        Database  db;
        string    sqlCommand;
        DbCommand dbCommand;


        db         = DatabaseFactory.CreateDatabase();
        sqlCommand = "[dbo].gspTMSApplicationDetails_SEARCH";
        dbCommand  = db.GetStoredProcCommand(sqlCommand, adApplicationId, adSenderId, adReceivedId, adReplyID, adApplicationFor, adSubject, adDescription, adLeaveFromDate, adLeaveToDate, adDate, adStatus, adMinitorID, adSentTo, adExtra1, adExtra2, adCasualLeave, adPaidLeave, adSickLeave, adEarnedLeave, adOtherLeave, adApproveStatus, adApproveByID, adApproveByType, adApproveDate);

        ds = db.ExecuteDataSet(dbCommand);
        ds.Tables[0].TableName = TABLE_NAME;
        return(TMSApplicationDetails.MapFrom(ds));
    }
    public static TMSApplicationDetails[] MapFrom(DataSet ds)
    {
        List <TMSApplicationDetails> objects;


        // Initialise Collection.
        objects = new List <TMSApplicationDetails>();

        // Validation.
        if (ds == null)
        {
            throw new ApplicationException("Cannot map to dataset null.");
        }
        else if (ds.Tables[TABLE_NAME].Rows.Count == 0)
        {
            return(objects.ToArray());
        }

        if (ds.Tables[TABLE_NAME] == null)
        {
            throw new ApplicationException("Cannot find table [dbo].[TMS_ApplicationDetails] in DataSet.");
        }

        if (ds.Tables[TABLE_NAME].Rows.Count < 1)
        {
            throw new ApplicationException("Table [dbo].[TMS_ApplicationDetails] is empty.");
        }

        // Map DataSet to Instance.
        foreach (DataRow dr in ds.Tables[TABLE_NAME].Rows)
        {
            TMSApplicationDetails instance = new TMSApplicationDetails();
            instance.MapFrom(dr);
            objects.Add(instance);
        }

        // Return collection.
        return(objects.ToArray());
    }
    public static TMSApplicationDetails[] MapFrom(DataSet ds)
    {
        List<TMSApplicationDetails> objects;

        // Initialise Collection.
        objects = new List<TMSApplicationDetails>();

        // Validation.
        if (ds == null)
        throw new ApplicationException("Cannot map to dataset null.");
        else if (ds.Tables[TABLE_NAME].Rows.Count == 0)
        return objects.ToArray();

        if (ds.Tables[TABLE_NAME] == null)
        throw new ApplicationException("Cannot find table [dbo].[TMS_ApplicationDetails] in DataSet.");

        if (ds.Tables[TABLE_NAME].Rows.Count < 1)
        throw new ApplicationException("Table [dbo].[TMS_ApplicationDetails] is empty.");

        // Map DataSet to Instance.
        foreach (DataRow dr in ds.Tables[TABLE_NAME].Rows)
        {
            TMSApplicationDetails instance = new TMSApplicationDetails();
            instance.MapFrom(dr);
            objects.Add(instance);
        }

        // Return collection.
        return objects.ToArray();
    }
    public static TMSApplicationDetails Get(System.Int64 adApplicationId)
    {
        DataSet ds;
        Database db;
        string sqlCommand;
        DbCommand dbCommand;
        TMSApplicationDetails instance;

        instance = new TMSApplicationDetails();

        db = DatabaseFactory.CreateDatabase();
        sqlCommand = "[dbo].gspTMSApplicationDetails_SELECT";
        dbCommand = db.GetStoredProcCommand(sqlCommand, adApplicationId);

        // Get results.
        ds = db.ExecuteDataSet(dbCommand);
        // Verification.
        if (ds == null || ds.Tables[0].Rows.Count == 0) throw new ApplicationException("Could not get TMSApplicationDetails ID:" + adApplicationId.ToString()+ " from Database.");
        // Return results.
        ds.Tables[0].TableName = TABLE_NAME;

        instance.MapFrom( ds.Tables[0].Rows[0] );
        return instance;
    }