Data entity representation
WEBSHARP can use two ways in the performance of data.
In the first way, fully utilize the functionality of DataSet in the .NET Framework class library, and designed an EntityData class. This class inherits DataSet and adds some properties and methods. With the map of the database, the way XML configuration file is used. XML configuration files can be generated by our tools.
In actual applications, you have to get a product entity object, which can be obtained by getting:
EntityData Product = EntityProtypeManager. Getemptyentity ("product");
Then, the properties of this object can be accessed by the following manner:
String Productid = Customer ["ProductID"]
It can be seen that this way is a bit different from purely object-oriented way. In this way, the performance of the data is only one, that is, EntityData. The advantage is obvious. It is not necessary to write a class separately to each entity, which can greatly reduce the number of code. Its shortcomings are also very obvious, that is, it is not possible to use the compiler type detection. If you call the object's properties, the name of the wrong property may be wrong, however, this problem can be solved by tools. This way, compare the habit of using the ADO programmer.
In the second way, we can write a product class, then use this class according to the standard OO method. Just, when writing a Product class, you must implement the persistencecapable interface, and you can use the powerful features of the EntityData class.
The definition of the PersistenceCapable class See: Websharp main interface definition --PersistenceCapable
An example of a Product class implemented in accordance with this standard is as follows:
Public Class Product: PersistenceCapable
{
Private EntityData Product;
Public product (): this (true)
{}
Public Product (Bool Autoinit)
{
Product = EntityPrototypeManager.GeteMptyentity ("Product");
IF (Autoinit)
Product.newRecord ();
}
Public String ProductID
{
Get {return product.getstring ("productID");}
Set {product ["productID"] = value;
}
Public String Name
{
Get {return product.getstring ("name");
Set {product ["name"] = value;
}
Public String UnitName
{
Get {return product.getstring ("unitname");}
Set {product ["unitname"] = value;
}
Public String Description
{
Get {return product.getstring ("description");
Set {product ["description"] = value;
}
Public Decimal Price
{
Get {return product.getDecimal ("price");} set {product ["price"] = value;
}
Public Decimal Currentcount
{
Get {return product.getDecimal ("currentcount");}
Set {product ["currentcount"] = value;
}
Public int ObjectCount
{
get
{
Return Product.EntityCount;
}
}
Public EntityData EntityData
{
get
{
Return Product;
}
set
{
Product = Value;
}
}
Public bool next ()
{
Return product.next ();
}
Public void first ()
{
Product.first ();
}
Public void addnew ()
{
Product.newRecord ();
}
}
It can be seen that in this way, the Product class can represent either a single Product object, or a set of Product objects and can be traversed through the Next and First methods.