Sidechain Entity

From BiblePay Wiki
Jump to: navigation, search

Creating a new Entity

From the BiblePayCommon Project open the Entity.cs file. Search for "VideoRequest".

Create a strongly typed object that inherits from BaseEntity and IBBPObject (in the same way that VideoRequest does). Note that the BaseEntity fields are already present in new entities (for example, UserID, ID, and Height are already present) and you will receive an error if you try to use them again. Create a getter and setter (using VideoRequest as an example) for each public property.

Ensure there is a GetHash() function implemented using the Primary Key of the table.

For example, if your table expects edited data to rely on a UserID plus a SSNNumber, the primary key should be "UserID+SSNNumber". This would allow an Edit to occur.



How to Select Data

We currently support snippets similar to SQL WHERE clauses.

We return a standard Microsoft DataTable with the data.

DataTable dt = BiblePayDLL.Sidechain.RetrieveDataTable2(fTestNet, "VideoRequest", true);
dt = dt.FilterDataTable("processTime=0");

In this example, this is equivalent to "Select * from VideoRequest where processTime=0".

To order the data:

dt = dt.OrderBy("time desc");

This command orders the result set by time descending.


How to Insert data

Create a strongly typed object, for example this video record:

Populate the video record fields:

BiblePayCommon.Common.DACResult dResult = DataOps.InsertIntoTable(this, IsTestNet(this), videoRecord, gUser(this));

The above command will insert the videoRecord into the Video sidechain table, and charge the site approx. 1BBP for the insert.

The dResult will contain the TXID, an error or a null for the error field, and any optional fields (such as a URL if it was a blob).


How to UPDATE data

To update data, simply retrieve the strongly typed object, edit it and mirror what you did above with the insert:

BiblePayCommon.Common.DACResult dResult = DataOps.InsertIntoTable(this, IsTestNet(this), videoRecord, gUser(this));

BiblePay will detect the current record, make the changes, charge for the edit, and return a DACResult.