I
I
Ilya2013-11-19 07:44:50
C++ / C#
Ilya, 2013-11-19 07:44:50

Three-layer architecture for ADO.NET, problems when returning DBNull and little things

Hello. After reading this article about the three-layer data access architecture, I decided to finally learn how to write everything normally and according to the rules. Everything is fine so far, but there are a couple of questions:
1. If at this stage:

UserVO userVO = new UserVO();
            DataTable dataTable = new DataTable();

            dataTable = _userDAO.searchByName(name);
            foreach (DataRow dr in dataTable.Rows)
            {
                userVO.idUser = Int32.Parse(dr["t01_id"].ToString());
                userVO.firstname = dr["t01_firstname"].ToString();
                userVO.lastname = dr["t01_lastname"].ToString();
                userVO.email = dr["t01_email"].ToString();
            }
            return userVO;

If the value from the base comes DBNull, then assign data to the model object that cannot take such values ​​( For example: int , DateTime cannot be null ), then what checks are better to do and what to return to the model object?

2. If the base returns several rows ( for example, in the DataGridView control or just a list ), then I add them to the List< T >, where T is the model class (Model Layer or as in the example above UserVO). Am I doing the right thing?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2013-11-19
@msc

1. Use Nullable in the model.
2. Yes.
But, IMHO, I would look at the Entity Framework, NHibernate or other ORMs, since ADO, although it works quickly, is now only suitable for projects at the support stage. If you write everything anew (as I understand it with you), then it is better to take a step into the present. Of the benefits: much less need to write code for working with the database, LINQ.
EntityFramework
NHibernate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question