Casually write, Petapoco with MySQL use, in a industrial control project to fully use to save a lot of development time, experienced the efforts of the half a year close to completion of the project, the customer does not recognize the account, the beginning of the demand contract is a failure, technology or only to solve technical problems!
On the code!
Enquiry Service
Public classBaseviewmodel {#regionCreate DataBase, if not exitPrivateDatabase _db; PrivateDatabase Db {Get { if(_db = =NULL) _db=NewDatabase ("Connectionstringmysql"); return_db; } } #endregion #regionCommon Curd PublicT get<t> (stringID) {returnDb.singleordefault<t>(ID); } PublicList<t> getall<t>() { varClassName =typeof(T). ToString (); vararg =classname.substring (Classname.lastindexof ('.') +1, Classname.length-Classname.lastindexof ('.') -1); returnDb.fetch<t> (string. Format ("SELECT * from {0};", Arg)); } Public voidSave (Objectobj) {db.save (obj); } Public intUpdate (Objectobj) { returndb.update (obj); } Public intDelete (Objectobj) { returndb.delete (obj); } #endregion }
Connection string
<add name="connectionstringmysql" connectionString=" Server=localhost;database=autoapp; Uid=root; Pwd=root;charset=utf8;pooling=true; " providerName="MySql.Data.MySqlClient"/>
Don't forget to install Mysql-connector C #, go to the official website.
Don't see the add-ons? You need the demo code to leave the mailbox.
Petapoco and MySQL