6

We are developing a project in ASP.NET/C# which is a not a very large project but a sizeable one. Currently we have developed few pages. I am talking from point of view of a single page right now.The approach is followed for every pages that has been developed so far.

In the code behind of my page we use Linq To SQL queries directly. The insert operation is done , queries to fill dropdownlists and other database related operations are used in code behind itself.

We use functions though.The same goes for other pages as well.

My question is should I include them in class files and then create objects and call appropriate methods to do my stuff?

If yes, should we create a single class or create one class per page. Is this called creating Data Access Layer.

Can anyone help me suggest a proper way to do this?

Is this approach a good programming practice.

This is a simple function that we are using in our code behind

public void AccountTypeFill()
        {
            //Get the types of Account ie Entity and individual
            var acc = from type in dt.mem_types
                       select type.CustCategory;
            if (acc != null)
            {
                NewCustomerddlAccountType.DataSource = acc.Distinct().ToList();
                NewCustomerddlAccountType.DataBind();  
            }
        }

Can anyone point a simple example referring to this query?

I hope my question makes sense. Any suggestions are welcome.

torrential coding
  • 1,755
  • 2
  • 24
  • 34
Priyank Patel
  • 6,898
  • 11
  • 58
  • 88

1 Answers1

8

Don't hard-code in the code-behind. Use Classes and it is not a matter of one class for each page.

These links will help:

Designing A Data Access Layer in LINQ to SQL

Can LINQ to SQL generated objects be decoupled?

Where to put method code which is called on click of a button?

LINQ to SQL and the repository pattern

Decoupling Business Logic Layer from the User Interface Layer using C#

Community
  • 1
  • 1
Geek
  • 429
  • 2
  • 5