1. Using Fluentnhibemate to manipulate the database, add maps to the database

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.