MySQL support is added to component v1.7 (MySQL 5.1 is tested ).
The following shows how to use it.
First add connectionstring
<add name="MySQLConnectionString" connectionString="server=192.168.1.175;user id=root; password=huxj; Port=3306;database=test;" providerName="Hxj.Data.MySql" />
public static DbSession MySqlTest = new DbSession("MySQLConnectionString");
A new table mtable is created in the test database. There are only two fields: Mid int auto-increment, mname varchar (50)
Then, use the object generation tool to generate an object.
The code for adding data to the test is as follows:
Mtable m = new Mtable();m.Mname = Hxj.Common.StringHelper.GetRandomString();int returnValue = Db.MySqlTest.Insert<Mtable>(m);
The generated SQL statement is as follows:
Text:
INSERT INTO `mtable` (`mname`) VALUES (?swbeetoamhazjwa);select last_insert_id();
Parameters:
?swbeetoamhazjwa[String] = wzfJPJIDvKPP15HKRyxO4w==
Then test batch addition:
using (DbBatch batch = Db.MySqlTest.BeginBatchConnection(5)){ for (int i = 0; i < 10; i++) { Mtable m = new Mtable(); m.Mname = Hxj.Common.StringHelper.GetRandomString(); batch.Insert<Mtable>(m); }}
The generated SQL statement is as follows:
Text:
INSERT INTO `mtable` (`mname`) VALUES (?tksvpwwdiguovrlq);INSERT INTO `mtable` (`mname`) VALUES (?ttnbgzirzhvlssuv);INSERT INTO `mtable` (`mname`) VALUES (?eotxpjjzywvzzcro);INSERT INTO `mtable` (`mname`) VALUES (?xemplfkdzouwbwzx);INSERT INTO `mtable` (`mname`) VALUES (?ulyiapnhhwkufzxn);
Parameters:
?tksvpwwdiguovrlq[String] = oYCY91wzpUnDA5TOiPtL9g==
?ttnbgzirzhvlssuv[String] = TEtLPO3QvuUEGeHTuoufhw==
?eotxpjjzywvzzcro[String] = k0Gs4Ndf4Kjp/1m973CMwA==
?xemplfkdzouwbwzx[String] = MIH1LPkpa2HwPnIJmNUmnA==
?ulyiapnhhwkufzxn[String] = NIni89feCPwRLspG1BFevg==
Text:
INSERT INTO `mtable` (`mname`) VALUES (?rkqfafnpxtfyqaka);INSERT INTO `mtable` (`mname`) VALUES (?ymfmodryykkiozcc);INSERT INTO `mtable` (`mname`) VALUES (?ztwdwxcwnkrdfzvd);INSERT INTO `mtable` (`mname`) VALUES (?pugtkuoehuqavxch);INSERT INTO `mtable` (`mname`) VALUES (?igthuzfzqopddexr);
Parameters:
?rkqfafnpxtfyqaka[String] = u/rxTfVKLkvymn5+U3gARA==
?ymfmodryykkiozcc[String] = ypsRx4kDZPjH/MRrwoHegA==
?ztwdwxcwnkrdfzvd[String] = DnzF82DWq5313Vg7LWPKxA==
?pugtkuoehuqavxch[String] = qNQ058RJ4fZSDQocALGVaQ==
?igthuzfzqopddexr[String] = 9fv5ZpttbcicvT5M573jGA==
Five SQL statements are executed in combination once.
Then perform the query:
Db.MySqlTest.From<Mtable>().Page(10, 2).ToList();
The generated SQL statement is as follows:
Text:
SELECT * FROM `mtable` ORDER BY `mtable`.`mid` ASC limit 10,10
In other examples, the code is no longer displayed, and the operations are the same as before.
Download