How to access data. Working

I am new to C # developer. When I just started learning programming, the intricacies were pretty simple, you see a problem, you develop a solution, test it, and it works, it's simple.

Then you will learn the design patterns and the whole abstraction, and you will begin to spend more time on code that does not produce any results, always wearying the code from any possible changes in the future. More time less.

Sorry for the boring introduction, but I'm just trying to show how upset I am now. There are many data access technologies provided by Microsoft itself, and an even wider range of technologies provided by third-party companies.

I don’t have a team leader or a super experienced programmer’s neighbor, so I should ask you for advice.

How do you understand data access in your real applications written in C #?

+7
c # database visual-studio
source share
3 answers

From a very general point of view, I always hide the details of data access data behind the interface, for example:

public interface IRepository<T> { /*...*/ } 

The .NET framework offers many different ways to access data, so I can understand that you are confused. However, at the moment there are only two or three reasonable options for accessing relational databases:

+2
source share

It is often difficult to understand the benefits of abstraction without seeing the benefits that it provides in the real world. The best advice I can give is to familiarize yourself with the principles of SOLID, and then when writing the application, try to think about how the client can come to you and say "Now I need to do this", which can be a subtle change in functionality or a major change. Think about how this will affect your code and how many places you will need to make these changes. Once you make these changes, how confident are you that you haven't broken something else?

Another idea is to download one of the sample applications. One of my favorite examples is the Data Access Platform Example provided on Codeplex. Try to execute this code and see how the implementation of abstraction and templates minimizes the impact on the code as a whole when the time comes for a change.

The bottom line is that it's easy to learn a programming language, but understanding how to create robust solutions takes time. Stick to this because when you finally get a good understanding of the software architecture, it is very helpful.

+1
source share

Some points to consider for DAL: (note: very stubborn, but there should be answers to this question)

  • Encapsulate logic in the Repository
  • Use encoding with interface
  • Use dependency injection
  • Use a mature ORM like NHibernate / Entity Framework 4.0 (but you know when to use SPROC to work with db intensity).
  • Use the Unit of Work template .
  • Prevent SQL Injection attacks with parameterized queries (or LINQ-Entites as described above)
+1
source share

All Articles