Question: **Method 1:**

```
  public class1
  {
     private string _val1;
     private string _val2;

     public string Value1
     {
       get {return _val1;}
     }

     public string Value2
     {
       get {return _val2;}
     }

     public void ReadingDataFromDB()
     {
        //code to retrieve data from database
        if(Reader.read())
        {
          _val1 = reader["val1"].ToString();
          _val2 = reader["val2"].ToString();
        }
     }
  } 

```

**Method 2:**

```
public class1
{
   public void ReadingDataFromDB(out string _val1, out string _val2)
   {
      _val1 = "";
      _val2 = "";
      //code to retrieve data from database
      if(Reader.read())
      {
        _val1 = reader["val1"].ToString();
        _val2 = reader["val2"].ToString();
      }
   }
 } 

```

In the **Method 1** class has properties, but in **Method 2** class has a method with output parameters. Both can be used to retrieve data from the database.

I have seen that often **Method 1:** is used for Business Logic and **Method 2** is used for Data Access. 

My question is, from the above **Method 1** and **Method 2** what is the better one for using in data access classes? And are there any specific reasons for that other than personal opinion?

Answer: 
I suggest something like that (Method 1 improved or Method 3):

```
  public class MyClass {
    //TODO: find better names for Value1, Value2
    public String Value1 {get; private set}
    public String Value2 {get; private set}

    // static: the method actually creates an instance as read form DB
    public static MyClass ReadFromDB() {    
      //TODO: Create a connection, SQL command here

      if (Reader.Read()) {
        return new MyClass() {
          // Do not forget about NULL
          Value1 = reader["val1"].IsDBNull ? null : Convert.ToString(reader["val1"]),
          Value2 = reader["val2"].IsDBNull ? null : Convert.ToString(reader["val2"])
        } 
      }
      else
        return null; // or throw an exception - no data in DB
    }
  }

...

  MyClass test = MyClass.ReadFromDb();

  Console.Write(test.Value1);

```

As for suggestions in the question: *Method 2* ruins data incapsulation: it returns two `string`s when we expect corresponding properties (since we're working with `class1`); yet another problem is that `out`'s are hard to read. As for *Method 1*, we usually expect that "ReadingDataFromDB" will read data from the database and return the intance (of `class1`) that's why I redesign the method into `static` and add `return`.
Take a look at an `ORM`, the [EntityFramework](https://msdn.microsoft.com/de-de/data/ef.aspx) for example.

However:

Basicly you should have a Model:

```
class FooModel {
    public string Value1 {get;set;}
    public string Value2 {get;set;}
}

```

And a Repository:

```
class FooRepository {
   private _db;

   public FooRepository(SqlConnection db) {
       _db = db;
   }

   public FooModel GetFooModelById(int id) {
       //...
       var model = new FooModel {
           Value1 = reader["val1"].ToString(),          
           Value2 = reader["val2"].ToString()          
       };
       //...
   }

   public List<FooModel> GetFooModelCollection() {
       //...
   }

}

```

To bring it together:

```
var connection = new SqlConnection(...);
var repo = new FooRepository(connection);
var myFoo = repo.GetFooModelById(42);

```