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


        instance = new TMSTelephoneDetails();

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

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

        instance.MapFrom(ds.Tables[0].Rows[0]);
        return(instance);
    }
    public static TMSTelephoneDetails[] Search(System.Int64?tdTelephoneId, System.String tdTelephoneDepartment, System.String tdTelephoneNumber, System.DateTime?tdDate, System.Int32?tdStatus)
    {
        DataSet   ds;
        Database  db;
        string    sqlCommand;
        DbCommand dbCommand;


        db         = DatabaseFactory.CreateDatabase();
        sqlCommand = "[dbo].gspTMSTelephoneDetails_SEARCH";
        dbCommand  = db.GetStoredProcCommand(sqlCommand, tdTelephoneId, tdTelephoneDepartment, tdTelephoneNumber, tdDate, tdStatus);

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


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

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

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

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

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

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

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

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

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

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

        instance = new TMSTelephoneDetails();

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

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

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