Hands-on instructions on how to build a three-tier architecture using the soft. Net Code Generator

Source: Internet
Author: User

I started to learn. net from the university for three years. During the school period, I learned to build a three-tier architecture and write it myself. When I got out of my internship, I found that the three layers could still be soft. net.CodeThe following are the basic steps for generating a three-tier architecture:

Development Environment and tools:

Mobile Software. Net code generator version 2.17

    • Vsualmaxcompute 2008
    • SQL Server2000 Database
    • Er studio database modeling tool

Let's start:
First, design the database of my system in erstudio. First, design the logical model (Logical Model)

 

After the database logic model is completed, we use erstudio to generate the physical model (physic model)

Finally, the link generates SQL server into our database bo_blog. Since the focus is on the following, I will not demonstrate how to use er studio one by one.

Open the software. Net code generator, and select Add SQL Server 2000 server in the upper right corner.
 

Select the database type. Here is SQL 2000.

Enter database data connection information

After successfully connecting to the database, we can see that the database table list is the same as that in SQL Server Enterprise Manager.

 

We select the bo_blog database for our project and select the generate code project of the intermediate option.

Then select a simple three-tier architecture and fill in the solution name. Here I write myblog and select the Save path. Here I save it on the desktop.

Then select database bo_blog and all the tables in the database will be listed on the left.

We add all the tables to the right border.

Here we want to set the namespace in each project in the solution. Here I set all the namespaces to myblog, and click Start to generate

This will automatically generate a solution for the entire three-tier architecture

However, the entire solution generated in this way cannot be compiled through vs 2008, and many errors will be reported. We have to streamline and modify it.

Next, follow what I said.

Open the generated solution and delete all. SLN. csproj and. csproj. delete the entire web folder. Only the LTP in the Lib folder is retained. common. DLL file, dbhelpersql in the dbutility folder. CS file, we also create a solution in the original folder, and then add the model BLL Dal dbutility lib class library project to the solution we created following the method below.

For more information, see the following steps.

Create solution bo_blog on the desktop

When creating a project in Vs, select. NET Framework 2.0.

After creating a new solution, we will create Bll, Dal, dbutility, Lib, and model class libraries in the solution to create an ASP. NET web application.ProgramProject

Then we copy the files under the BLL Dal model lib dbutility that we generated and sorted to the corresponding folder of our new solution.

After the copy is completed, select a project in the current solution.

And then select the show all files button above Solution Properties

In this way, the file we assigned will appear below, represented by dotted lines.

Then, press Ctrl to select all of them, right-click and select "include in Project"

In this way, we can attach them to this class library project.

In this way, we will attach other files to the Dal, Lib, model, and dbutility projects.
Next, we need to associate several projects in the solution and add references between them.
We chose to reference the project. In Bll, we want to reference the two projects dal and model.

CTRL + Left click to select the dal and model, and click OK.

CTRL + Left click to select the dal and model, and click OK.

Then we will reference the DLL file in a lib project in BLL. In the same way, add reference-> browse-> Find the Lib project and select LTP in it. common. DLL file, click OK

In the same way, we will reference dbutility and model in the Dal project.

Then, we need to add the system class system. configuration to the dbutility project by adding the reference->. Net-> locate system. configuration, and then click OK.

Then, open the Web. config configuration file in the web project and add

Copy content to clipboard

Code:

<Deleetask>
<Add key = "webdal" value = "myblog. sqlserverdal"/>
<Add key = "webconnectionstring" value = "Server = localhost; initial catalog = bo_blog; uid = sa; Pwd = ***"/>
</Appsettings>

Such a database link configuration

Find the dbhelpersql. CS file in the dbutility project, and use

Copy content to clipboard

Code:

Configurationmanager. deleetpipeline ["webconnectionstring"];

String replacement

Copy content to clipboard

Code:

Pubconstant. connectionstring

Of course, you can also not write the connection string in the web. config file, just write it here.

Well, it's hard to write.
It's really hard. If you haven't finished writing it, forget it here.
If someone wants to use it, you can send a mailbox 332704948@qq.com if you have any questions.
You can use a code generator to generate a large part of the code used to build a perfect development foundation for you. It can also automatically generate stored procedures for common database Methods
It saves you time on Code, although it is a bit difficult to build an architecture.
Of course there are other code generators, which are better than this one. You can also try it.
First.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.