1. Create a console project Mysqldatebase
2. Additions to the project Fluent NHibernate Mapping tool
Click Manage NuGet packages , Click Browse, search for Fluent NHibernate
Click Install. when the installation is complete, the project reference adds a Fluent NHibernate and NHibernate
3. manually start the MySQL service
4. Run MySQL Front to view the database
Game Database name
TestUser is a table used for testing , followed by the main data in this table to operate
5. return vs start writing code formally
Create a folder called Model, Add a new class under the folder TestUser
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 usingfluentnhibernate.mapping;//using namespaces for mapping7 8 namespaceMysqldatebase.model9 {Ten /// <summary> One ///used to map the TestUser class to the TestUser table A /// </summary> - classTestusermap:classmap<testuser> - { the //using construction method to indicate the mapping relationship between Tesuser class and TestUser - PublicTestusermap () - { - //here x represents the object of the TestUser class +Id (x = x.id). Column ("ID");//Set ID property to primary key -Map (x = x.username). Column ("username");//Set the Username property to the username field +Map (x = X.password). Column ("Password");//set the Password property to the password field AMap (x = x.age). Column (" Age");//set the Age property to the Age field atTable ("testuser");//indicates a testuser table in the database - } - } -}
1. Using Fluentnhibemate to manipulate the database, add maps to the database