Practice ORM, create a GROVE-based .NET application (1)

zhaozj2021-02-16  51

Practice ORM, create a GROVE-based .NET application (1)

Writing Lin Xuepeng cnlxp@msn.com

For most software development projects, data is stored in the relational database, and the developers must be familiar with the SQL statement syntax and rules, and in many cases, developers need to write SQL statements, and have to consider transactions. Processing, logic analysis, etc., resulting in the SQL statement in the entire project, it has brought hindrance to the readability and maintainability of the program. At the same time, when the new project is joined, many places have to re-coding. Some big and complicated related code, why are you reusable? In addition, the programmer's requirements are high, the program calls are troublesome, but also to debug the program, but also debug SQL statement, many times the SQL statement contains some logical partial processing, which is very unscientific.

In order to improve the flexibility, reusability of the project, OR-M (object character modeling) must be mentioned, and individuals believe that OR-M is decoupled, and the Or-M layer is added to the original complex system. Make the system more easily maintained and upgraded. For example, in the previous system, change a database field, and all places that the corresponding use to this field will change, which may bring a lot of workload, and After the application, the code of the business logic layer is almost no change. Correspondingly, the call is not changed, and the change may only have those places that are mapped. Since the focus of this article is not OR-M, the specific information about OR-M will see the last reference.

Currently, there are many ORM methods under .NET, there are three types, one is the physical class mapping mode, and the other is to describe the XML, and the third is the XML and the entity class (such as the objectspaces of MS).

This article demonstrates how to use Grove Tool Kit to create a Grove-based simple web application. Grove is a reusable development component based on Microsoft .NET Framework, supports a variety of different database projects, providing standard two-layer, three-layer, and multi-layer development frameworks.

Introduction

Grove Develop Component Kit includes both part of Grove Develop Component and Grove Tool Kit;

Grove Develop Component is a reusable development component based on Microsoft .NET Framework, supports a variety of different database projects, providing standard two-layer, three-layer, and multi-layer development frameworks.

Grove Development Component combines the keyboard-oriented software development principle (generally design mode), focusing on improving the code reuse in software development, making software development architectures clear, facilitating speeding software development speed, reducing software maintenance costs.

Grove Tool Kit is an add-on-a-set-to-reusable code that is provided by Grove Development Component, which helps preview or generate reusable code depends on the Grove component, including the entity definition class, XML entity description ( XML Definition for Data Store, etc.

The greatest feature of Grove Tool Kit is that the relationship between the tool itself is debugged, associated with multi-tables, and generates a mapping entity or XML mapping description of a multi-table query.

installation

Install Grovekit Requirements VS.NET 2002 or 2003 and .NET Framework 1.0 or 1.1, this article is as an example of .NET Framework 1.1 and VS.NET 2003. Grovekit installation package (Grovekit.zip), you can get from http://grove.91link.com.

installation steps:

1. Unzip Grovekit.zip and perform the installation

2. Perform the Grove Install on your desktop to complete the installation task

Create a GROVE-based web project

After the Grovekit installation is over, open vs.net, on the VS.NET launch screen, you will see the logo of the Grove Develop Kit, indicating that the GroveKit has been properly installed.

This article will take C # ASP.NET project as an example, item name WebApp1, operating system Windows 2000, Database SQL Server 2000, Database Installement Name: WebApp1, Table Structure Definitions

Table Field Customers Customerid Int (4) Pkcustomername VARCHAR (50) CustomerDesc VARCHAR (200) Addresses AddressId Int (4) PKCustomerid Int (4) Address Varchar (200)

1) In vs.net, open "File -> New-> Project", select the ASP.NET web application in Visual C # project, determine the webapp1 project, add folder Entities (entity) in the project, Managers ( Façade layer), entitydb (database layer), add reference to Grove.dll, Grove.dll is located under the Grovekit installation path, you can also add Grove to the program cache through .NET Configuration.

2) In VS.NET, open Tools -> Grove Tool Kit, set the database connection properties in GroveToolkit, and save it.

Figure 1. Set the database connection string

3) Create a logfiles folder under the current project path C: / INETPUB / WWWWROOT / WebApp1, and configure Web.config current web project (add the following configuration before )

4) Select Entities in the VS.NET Solution Explorer and select the table name in GroveToolkit, click on the Preview Entity Class button in the GroveToolkit Toolbar, the entity map preview window of the table appears.

Figure 2. Preview entity mapping class

5) Check the namespace of the current preview entity class, here should be changed to WebApp1.entities, click the Generate File button, which will be generated to the Solution Explorer The currently selected path. 6) Repeat 4, 5 steps to generate mapping entity classes for other tables.

Customer.cs

Using system;

USING GROVE.DATAOBJECT;

[DataTable ("Customers")]]]]]

Public Class Customer

{

INT _CUSTOMERID;

String_customername;

String_customerdesc;

[Keyfield ("Customerid")]]]

Public Int Customerid

{

Get {return this._customerid;

Set {this._customerid = value;

}

[DataField ("Customername")]]]]

Public String Customername

{

Get {return this._customername;

Set {this._customername = value;

}

[DataField ("CustomerDesc")]]]

Public String CustomerDesc

{

Get {return this._customerdesc;}

Set {this._customerdesc = value;

}

Address.cs

Using system;

USING GROVE.DATAOBJECT;

[DataTable ("Addresses")]]]

Public Class Address

{

INT _ADDRESSID;

INT _CUSTOMERID;

String_address;

[Keyfield ("AddressID")]]]

Public int AddressID

{

Get {return this._addressid;

Set {this._addressid = value;

}

[DataField ("Customerid")]]]]

Public Int Customerid

{

Get {return this._customerid;

Set {this._customerid = value;

}

[Datafield ("Address")]]]]]

Public String CustomerAddress

{

Get {return this._address;}

Set {this._address = value;

}

}

Code 1. Entity mapping class

转载请注明原文地址:https://www.9cbs.com/read-25365.html

New Post(0)