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

zhaozj2021-02-16  46

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

Writing Lin Xuepeng cnlxp@msn.com

7) Add a CustomerDB class under the EntityDB of the current project, which is responsible for the operation of Customer database, including adding, deleting, modifying.

8) Repeat 7 and complete the AddressDB class.

Customerdb.cs using system;

Using Webapp1.entities;

USING GROVE;

USING GROVE.DATAOBJECT;

Public Class Customerdb

{

Public CustomerDB ()

{

}

Public void insert (Customer C)

{

IOBJECTOPERATOR OO = ObjectoperatorFactory.getObjectoperator ();

o.begintranscation ();

Try

{

o.insertObject (c);

o.commit ();

}

Catch (System.exception E)

{

Oo. rollback ();

Throw e;

}

oo.dispose ();

}

Public void delete (Customer C)

{

IOBJECTOPERATOR OO = ObjectoperatorFactory.getObjectoperator ();

o.begintranscation ();

Try

{

OO.RemoveObject (c);

o.commit ();

}

Catch (System.exception E)

{

Oo. rollback ();

Throw e;

}

oo.dispose ();

}

Public Void Update (Customer C)

{

IOBJECTOPERATOR OO = ObjectoperatorFactory.getObjectoperator ();

o.begintranscation ();

Try

{

oo.UpdateObject (c);

o.commit ();

}

Catch (System.exception E)

{

Oo. rollback ();

Throw e;

}

oo.dispose ();

}

Public EntityData SelectAll ()

{

IOBJECTOPERATOR OO = ObjectoperatorFactory.getObjectoperator ();

IObjectQuery oq = objectQuery (TypeOf (Customer));

EntityData Customers = New EntityData ();

Oq.execute (Customers);

oo.dispose ();

Return Customers;

}

} Addressdb.cs using system;

Using Webapp1.entities;

USING GROVE;

USING GROVE.DATAOBJECT;

Public class addressdb

{

Public addressdb ()

{

}

Public void insert (Address A)

{

IOBJECTOPERATOR OO = ObjectoperatorFactory.getObjectoperator ();

o.begintranscation ();

Try

{

o.insertObject (a);

o.commit ();

}

Catch (System.exception E)

{

Oo. rollback ();

Throw e;

}

oo.dispose ();

}

Public void delete (address a) {

IOBJECTOPERATOR OO = ObjectoperatorFactory.getObjectoperator ();

o.begintranscation ();

Try

{

oo.removeObject (a);

o.commit ();

}

Catch (System.exception E)

{

Oo. rollback ();

Throw e;

}

oo.dispose ();

}

Public Void Update (Address A)

{

IOBJECTOPERATOR OO = ObjectoperatorFactory.getObjectoperator ();

o.begintranscation ();

Try

{

oo.updateObject (a);

o.commit ();

}

Catch (System.exception E)

{

Oo. rollback ();

Throw e;

}

oo.dispose ();

}

Public EntityData SelectAll ()

{

IOBJECTOPERATOR OO = ObjectoperatorFactory.getObjectoperator ();

IOBJECTQUERY OQ = OO.NEWQUERY (TypeOf (address));

EntityData Addresses = new entrydata ();

oq.execute (addresses);

oo.dispose ();

Return Addresses;

}

}

Code 2. Database class

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

New Post(0)