Recently, I encountered some questions when I was working on some web projects. when I started development, I thought as long as the function was done. but after a long time, I want to do some well-structured and quality projects on my own. however, I still have some questions. let's talk about it here.
The first is about the layer-3 architecture. I read a lot of things online. but most of them are the same. it is generally called an object class. data Layer and business layer. I still understand this idea. however, the differences between the data layer and the business layer are not clear. I personally feel that the operations at the data layer are the same as those at the business layer. for example, a user table. I may create an object class in the model. then, perform some operations on the object class in the data layer. for example, add a user and obtain details of the user according to the user ID. however, at the business layer, I still write these methods and then call the methods in the data layer. basically, there is no change. sometimes I think this business layer is necessary.
Business Layer =? Data layer, hope you can give me some advice.
The second is a small problem:
I would like to ask, for example, if I have two repeater on one page to bind data, do I use a stored procedure to return both tables or try to bind one table in two separate workshops. in this way, the efficiency is better.
For example, when a user information is obtained at the data layer
Code
Public Thistoryuser getuserbyid ( Int ID)
{
Sqlparameter [] Par = Sqlhelperparametercache. getspparameterset (connstr, " P_admin_gethistoryuser " );
Par [ 0 ]. Value = ID;
Par [ 1 ]. Value = 0 ;
Par [ 2 ]. Value = 1 ;
Thistoryuser user= New Thistoryuser ();
Using (Sqldatareader SDR = Sqlhelper. executereader (connstr, " P_admin_gethistoryuser " , Par ))
{
If (SDR. Read ())
{
User = New Thistoryuser ();
User. ID = Int . Parse (SDR [ 0 ]. Tostring ());
User. Username = SDR [ 1 ]. Tostring ();
User. userid = SDR [ 2 ]. Tostring ();
User. HTTP = SDR [ 3 ]. Tostring ();
User. weburl = SDR [ 4 ]. Tostring ();
User. IP = SDR [ 5 ]. Tostring ();
User. platformid = Int . Parse (SDR [ 6 ]. Tostring ());
User. adddate = Datetime. parse (SDR [ 7 ]. Tostring ());
}
}
Return User;
}
This sectionCodeWhat are their advantages and disadvantages?
I hope you can give me some suggestions. Thank you!