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


        instance = new TMSCountry();

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

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

        instance.MapFrom(ds.Tables[0].Rows[0]);
        return(instance);
    }
    public static TMSCountry[] Search(System.Int64?cntrId, System.String cntrCountry, System.Int32?cntrStatus)
    {
        DataSet   ds;
        Database  db;
        string    sqlCommand;
        DbCommand dbCommand;


        db         = DatabaseFactory.CreateDatabase();
        sqlCommand = "[dbo].gspTMSCountry_SEARCH";
        dbCommand  = db.GetStoredProcCommand(sqlCommand, cntrId, cntrCountry, cntrStatus);

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


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

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

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

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

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

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

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

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

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

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

        instance = new TMSCountry();

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

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

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