Make one class that acts as a tunnel for other classes method

  • Thread starter Thread starter Belarmino Vicenzo
  • Start date Start date
B

Belarmino Vicenzo

Guest
Well I have a bunch of solution in a project. And one of those is for data access. I'm creating a different class for each of the tables of the database and each class will only handle that table (I'm trying).


This is the main DA class

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;



namespace AcessoDeDados
{
public static class AcessoBD
{
// the first AccessoAutor is a type
public static AcessoAutor AcessoAutor { get; set; }



}

}

This is the class I want to "privatize" from the public and make it only available though the AcessoBD class

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;

namespace AcessoDeDados
{
public class AcessoAutor
{
//nomeCompleto, numeroBI, idCategoriaAutor



static string conStringMySQL = "BibliotecaConnectionString";

private AcessoAutor(){
}

public IList<string> GetAuthorCategories(){
IList<string> categorias = new List<string>();

//code here
return categorias;
}

}
}


So I made the constructor private and I'm trying to access it like this in the main

static void Main(string[] args)
{

var resultado1 = AcessoBD.AcessoAutor.GetAuthorCategories();

foreach (var cat in resultado1)
{
Console.WriteLine(cat);
}

Console.ReadKey();

}

but it returns null, idk why.

But if I make the constructor public and create a new instance

AcessoAutor a= new AcessoAutor();
var resultado= a.GetAuthorCategories();

foreach (var cat in resultado)
{
Console.WriteLine(cat);
}
it works and give the result well. There's no problem on the connection, as I said it work one way, but other it doesn't.

I could make it static, but if I did, I would only be able to access from the class name.

I want to make something like the first approach, the first class, will have properties of the other and though these properties I will call the methods.

Any guesses?


PS: If u think u need more info, just ask.


BP-LP 2005/2016 @ll rights reserved

Continue reading...
 
Back
Top