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


        instance = new TMSAchievementDetails();

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

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

        instance.MapFrom(ds.Tables[0].Rows[0]);
        return(instance);
    }
    public static TMSAchievementDetails[] Search(System.Int64?adAchievementId, System.Int64?adStudentId, System.Int64?adFacultyId, System.Int64?adSchoolId, System.Int64?adSchoolSubId, System.String adTitle, System.String adDescription, System.String adImage, System.DateTime?adAchievementDate, System.DateTime?adDate, System.Int32?adStatus)
    {
        DataSet   ds;
        Database  db;
        string    sqlCommand;
        DbCommand dbCommand;


        db         = DatabaseFactory.CreateDatabase();
        sqlCommand = "[dbo].gspTMSAchievementDetails_SEARCH";
        dbCommand  = db.GetStoredProcCommand(sqlCommand, adAchievementId, adStudentId, adFacultyId, adSchoolId, adSchoolSubId, adTitle, adDescription, adImage, adAchievementDate, adDate, adStatus);

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


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

        // 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_AchievementDetails] in DataSet.");
        }

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

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

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

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

        // 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_AchievementDetails] in DataSet.");

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

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

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

        instance = new TMSAchievementDetails();

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

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

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