1) query.
Query entities
DBTool db = new DBTool (Table. EventBaseSet); // specifies the Table
Db. Where = EventBaseSet. EventID _. Equals _ (3); // lock the record
Var data = db. GetEntity <EventBaseSet> (); // retrieves an object
Query specified fields
DBTool db = new DBTool (Table. EventBaseSet );
Db. Where = EventBaseSet. EventID _. Equals _ (32 );
Var name = db. GetOneField <string> (EventBaseSet. EventID _);
Multi-field Query
DBTool db = new DBTool (Table. EventBaseSet );
Db. Where = EventBaseSet. EventID _. Equals _ (32 );
Var row = db. GetDestinationFields (EventBaseSet. EnabledBodyHtml _, EventBaseSet. Days _);
Compound condition Query
DBTool db = new DBTool (Table. EventBaseSet );
Db. Where = EventBaseSet. EventID _. BiggerThan _ (32). And _
(EventBaseSet. EventName _. Contains _ ("hello"). OR _ (EventBaseSet. Days _. BiggerThan _ (22 ));
Nested Query
DBTool db = new DBTool (Table. EventBaseSet );
Db. Where = EventBaseSet. Creater_CreaterID _. Equals _ (CreaterSet. CreaterID _. SelectFrom _ (Table. CreaterSet). Where _(
CreaterSet. Name _. Repeated SSTR _ ("")));
Custom object query (including multi-Table query)
Var SQL = "Copied SQL statement ";
Var data = DBTool. Database. GetEntity <custom entity> (SQL );
Data insertion
DBTool db = new DBTool (Table. CitySet); // db. StartTransaction = true; // whether to enable transaction db. SetInsertField (CitySet. CName _, "City 1 ");
Db. SetInsertField (CitySet. CID _, "10001 ");
Db. SaveChanges ();
Var newID = db. NewID; // newly generated auto-incrementing primary key
Data Update operations
// Update data --------------
Db. SetUpdateField (CitySet. CName _, "City 1 ");
Db. SetUpdateField (CitySet. CID _, "1--1 ");
Db. Where =
CitySet.
CID _. Equals _ (2)
Db. SaveChanges ();
//-----------------------
Data deletion
Db. DeleteWhere (EventBaseSet. EventID _. Equals _ (2 ));
Db. SaveChanges ();
In addition to the above functions, I will show some of its other powerful functions.
- Use the jqurey paging plug-in pagenav. min. js
.(
<Script>
Var _ pageSum = Math. ceil (<% = ViewData ["Count"] %>/20 );
Var _ perCount = 20;
Var _ listDivID = "_ listDivID ";
Var _ listActionPlace = "MyPromotionList? IsCreate = true ";// These are only configurations. The following can be copied.
Function GetPage (currentPageIndex, pageSum ){
..............................
});
</Script>
Call the Page code of the background.
Public List <HallPromotion> GetHallPromotionList (int startIndex, int endIndex, string orderby)
{
DBTool db = new DBTool (Table. PromotionSet );
Db. Where = "1 = 1 ";
Var count = db. GetCount ();
Var list = db. GetPageListDesc <PromotionSet> (startIndex, endIndex, orderby); // specify the index page.
Var haList = new List <PromotionSet> ();
..........
Return ret;
}
2. Database Upgrade problems (we often face database table changes)
Do not worry about these things in Qin. Data, because the entity is all generated by the code generator. update the database once and you regenerate the DLL (the code generator has the compilation function)