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

zhaozj2021-02-16  45

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

Writing Lin Xuepeng cnlxp@msn.com

9) Add the CustomerManager class and the AddressManager class under the current project, and the Managers layer belongs to the business logic layer, which is responsible for another package of the entity database operation.

In the business logic layer, the class constructor is defined in private and implements the Singleton mode.

CustomerManager.cs Using System;

USING GROVE;

Using Webapp1.entities;

Using WebApp1.entitydb;

Public Class CustomerManager

{

Private CustomerManager ()

{

}

Public Static Void AddNewCustomer (Customer C)

{

CustomerDB DB = New CustomerDB ();

Db.insert (c);

}

Public Static Void Deletecustomer (Customer C)

{

CustomerDB DB = New CustomerDB ();

Db.delete (c);

}

Public Static Void UpdateCustomer (Customer C)

{

CustomerDB DB = New CustomerDB ();

Db.Update (c);

}

Public Static EntityData getAllCustomers ()

{

CustomerDB DB = New CustomerDB ();

Return db.selectall ();

}

} Addressmanager.cs using system;

USING GROVE;

Using Webapp1.entities;

Using WebApp1.entitydb;

Public Class AddressManager

{

Private addressmanager ()

{

}

Public Static Void AddNewdress (Address A)

{

AddressDB DB = New AddressDB ();

Db.insert (a);

}

Public Static Void Deleteaddress (Address A)

{

AddressDB DB = New AddressDB ();

Db.delete (a);

}

Public Static Void UpdateAddress (Address A)

{

AddressDB DB = New AddressDB ();

db.Update (a);

}

Public Static EntityData getAlladdresses ()

{

AddressDB DB = New AddressDB ();

Return db.selectall ();

}

}

Code 3.façade layer definition

10) Add the addition of Customer and Address, add the reference to the Façade layer to the Façade layer in the ASPX page. Insertion, modification, deletion, etc.

Simple example:

Customer C = New Customer ();

c.customername = "Tiantic Software";

c.customerdesc = "http://www.tryitsoft.com";

Customermanager.addnewcustomer (C);

11) In the Customers and Addresses tables, Customerid in the Addresses table is the PK (primary key) of the primary table Customers, so the property CustomeriD of the physical class address.cs, the bound DataField () can be changed to foreignkeyfield (), in a certain When Customer operation, you can get all the addresses of the customer in the following ways. ArrayList Addresses = new arraylist ();

IOBJECTOPERATOR OO = ObjectoperatorFactory.getObjectoperator ();

retrievechildObjects (C. Customerid, Addresses, TypeOf (Address);

12) When we need to develop quickly, it is necessary to consider the three or multi-layer applications, it is necessary to achieve the own persistence of the entity class, to achieve the own persistence of the entity class, must inherit Grove.DataObject.entityClassBase.

Simple example:

Customer C = New Customer ();

c.customername = "Tiantic Software";

c.customerdesc = "http://www.tryitsoft.com";

C.INSERT ();

13) *** About entity mapping multi-table relationship query. Click on the Build Relationship Query button in the Toolbar in GroveToolkit. The multi-table relationship query wizard appears. Select Entity Class Click Next, the RELATION Query Builder window appears, the lower half of the window is right-click to select "Add Table ..." or Toolbar in the window. Click the Add Existing Table button, add a table window, add a table Customers and Addresses.

Figure 3. Constructive entity mapping

In FIG. 3, click the field portion of the Customers table (hold down the left mouse button) to drag to the field area of ​​the Addresses table, and release the left mouse button, two tables related windows

Figure 4. Interval relationship attribute

After selecting the CustomerId column of the Addresses table in Figure 4, click OK, if you need to specify whether the two tables are left, right-associated, or all external associations, select Options under include Rows.

Figure 5. Relationship is generated

In Figure 5, right-click the Customers table to select SELECT All Column, or select Table Property to select the column you want to display.

Figure 6. Select the display column

In FIG. 5, select the column that the Addresses table needs to be displayed, and then click the execution button on the current window Toolbar. If the execution is executed, the execution result will be displayed in the current window, now click on the Preview Relation Query Class button on Toolbar, and preview the relationship entity Map class.

CustomersReranceQuery.cs Using System;

USING GROVE.DATAOBJECT;

[RELATIONTABLE ("CustomersReranceQuery", Beginwithtable = "Customers")]

Public Class CustomersReranceQuery

{

[RELATIONREFLECT ("Customers", "Addresses")]]]

[RELATIONFIELD ("Customerid", "AddressID")]

Public String Relationship_1 {

Get {return "[Customers]. [customerid] = [addresses]. [addressid]";

}

INT _CUSTOMERID;

[DataField ("Customerid", TableName = "Customers")]

Public Int Customerid

{

Get {return this._customerid;

Set {this._customerid = value;

}

String_customername;

[DataField ("Customername", TableName = "Customers")]]

Public String Customername

{

Get {return this._customername;

Set {this._customername = value;

}

String_customerdesc;

[DataField ("CustomerDesc", Tablename = "Customers")]]

Public String CustomerDesc

{

Get {return this._customerdesc;}

Set {this._customerdesc = value;

}

String_address;

[Datafield ("Address", Tablename = "Addresses")]]

Public String Address

{

Get {return this._address;}

Set {this._address = value;

}

}

Code 4. Relationship mapping entity class

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

New Post(0)