Asp.net multi-storey structure of the variables used in the transmission and
The company has been quick two weeks, but as a result of customer demand analysis is not down, all the projects has not yet begun. Take advantage of the time to carefully study the Asp.net multi-storey structure, the main reference is the one Wrox <. Net WebSite Programming Problem-Design-Solution>, personally feel that this writing well. To a certain extent-oriented. Net basis for the development of staff, the beginning may seem find it very difficult to understand, but look carefully will find that this book is an excellent application-oriented reference manual.
Asp.net multi-storey structure is mainly to solve the data layer, logic layer and said that the relationship between the layers. My approach is this: First, the establishment of a DataCore base class. Base class package inside some lower the basic operation of the database, for example, database access, call stored procedures and so on. In this place there are noteworthy, through a function of the override function can be called different storage process. The following code example:
Protected int RunProcedure (string storedProcName, IDataParameter [] parameters, out int rowsAffected)
(
Int result;
Connection.Open ();
SqlCommand command = BuildIntCommand (storedProcName, parameters);
RowsAffected = command.ExecuteNonQuery ();
Result = (int) command.Parameters [ "ReturnValue"]. Value;
Connection.Close ();
Return result;
)
Protected SqlDataReader RunProcedure (string storedProcName, IDataParameter [] parameters)
(
SqlDataReader returnReader;
Connection.Open ();
SqlCommand command = BuildQueryCommand (storedProcName, parameters);
Command.CommandType = CommandType.StoredProcedure;
ReturnReader = command.ExecuteReader ();
/ / Connection.Close ();
Return returnReader;
)
Protected DataSet RunProcedure (string storedProcName, IDataParameter [] parameters, string tableName)
(
DataSet dataSet = new DataSet ();
Connection.Open ();
SqlDataAdapter sqlDA = new SqlDataAdapter ();
SqlDA.SelectCommand = BuildQueryCommand (storedProcName, parameters);
SqlDA.Fill (dataSet, tableName);
Connection.Close ();
Return dataSet;
)
Protected void RunProcedure (string storedProcName, IDataParameter [] parameters, DataSet dataSet, string tableName)
(
Connection.Open ();
SqlDataAdapter sqlDA = new SqlDataAdapter ();
SqlDA.SelectCommand = BuildIntCommand (storedProcName, parameters);
SqlDA.Fill (dataSet, tableName);
Connection.Close ();
)
The reason is simple, one to see to understand. After operating for the benefit.
Second is to establish a logical layer, the logical layer is essentially DataCore examples of the data layer after layer for the return of some of that DataSet, DataReader or perform some type of insert, update, delete such statements. This is the logic of the Project in order to distinguish between different functional modules below. For example, user name called UserModel.cs module, the module is called NewsModel.cs so on. Another advantage of the logic that can be said of many examples of the establishment of an object or the same method. For example, User category, or by ID Username enquiries and the establishment of the object can be said of the multiple calls.
Finally, there is that layer that is the function of the completed pages logic. Is accepted then the client data integration and simple judgement passed to the logical layer. Similarly, the logic of the transfer to receive the Dataset or DataReader that prospects pages.
Data at all levels of the relationship between relative independence, but it is relatively continuous.
Independence:
For that several of the outside layer can be targeted to the individual or to directly take on other projects. Because everyone has is to realize independent functional model and complete. Because in the application of similar projects basically not much change, especially some of the more primitive relative, in this example the DataCore is a typical example.
Continuity:
Data transfer process in the strong continuity. For example, in that, there is a layer under Session in Userid return a Dataset, I originally wrote:
That layer:
DataSet UserInforRow = ObjectUser.GetUserInfor (Int32.Parse (Session [ "UserId"]. ToString ()));
Logic layer:
Public DataSet GetUserInfor (int UserID)
(
SqlParameter [] = (new SqlParameter parameters ( "@ UserID" SqlDbType.Int, 4));
Parameters [0]. Value = UserID;
Using (DataSet UserInfor = RunProcedure ( "GetUserInfor" parameters, "UserInfor"))
(
Return UserInfor;
)
)
This can be compiled, but suggested that in the implementation of the wrong time, type does not match, not above grammar mistakes. But a mistake in that layer is a coming-Int32, it is in a Sqlparameter Int, 4, originally thought that this type of the variable in each of the levels are relatively independent, but when they passed between the time of data there are problems.
On this issue, there are two solutions for the sake of change or changes that logic layer. Changes logic layer, it is necessary to change
SqlParameter [] = (new SqlParameter parameters ( "@ UserID" SqlDbType.Int, 32));
- Changes that should read:
DataSet UserInforRow = ObjectUser.GetUserInfor (int.Parse (Session [ "UserId"]. ToString ()));
Both options are obviously more reasonable changes that layer, because not because of a more variable transmission change in the logic layer can be said of other pages by calling method.
Other similar transfer and use of variables encountered similar problems, although several levels relatively independent, but in the transmission of data on the relatively continuous.
. Net in the web application of the above can be done very complicated logic strong, simple and not-call pages. Net is not a feature of the application. I am also a little contact, the tip of the iceberg,æŠ›ç –å¼•çŽ‰hope to play a role so that the Jianxiao.








0 Comments to “Asp.net multi-storey structure of the variables used in the transmission and”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.