NHibernate3 Anatomy: Mapping Overview of mapping articles

Source: Internet
Author: User
Tags in domain to domain visual studio 2010

Mapping overview

NHibernate as a typical ORM tool, we used to define domain first and then map the database relationship to domain, and the nhibernate mapping was in the form of an XML file. This article from the overall understanding of the next nhibernate mapping process and our way of writing.

Mapping processing process

When we confrontation NHibernate, what did nhibernate do to mapping part of the story?

    • Parse Read mapping file
    • Deserialize the mapping file (deserialize) to xmldeserialized (that is, the NHibernate.Cfg.MappingSchema.HbmMapping class)
    • bind The Hbmmapping class to a metadata map (mapping-metadate), (that is, the NHibernate.Cfg.Mappings class)
    • Build sessionfactory

Use a picture (from Fabio Maulo blog) to show the inner workings of nhibernate in detail:

Next we look at the various mapping methods of nhibernate.

Mapping Way

According to my long-term discovery, beginners are often the most eager to ask the question is "how do you usually write mapping files, is generated?", and ask questions sometimes when you post an XML map, you always post the mappings generated using the generator.

There are many ways to write nhibernate mappings now, such as:

    • Build tool Software (try not to use it)
    • Related open source projects (can be used)
    • Write XML manually (recommended)

As you can see from the above diagram, all of the above methods are ultimately generated as XML files and then processed according to the mapping process.

Build Tool Software

Now there are a lot of tools, such as commercial software: Codesmith, Visual NHibernate, open source software: mygeneration, NHibernate modeller, ajgenesis, etc.

Codesmith

Official address: http://www.codesmithtools.com/

NHibernate templates are available to generate mapping files as required.

Visual NHibernate

Official address: http://www.slyce.com/

is the latest Visual nhibernate mapping tool. Can try it, the effect is good.

Mygeneration

Official address: http://www.mygenerationsoftware.com/

Like Codesmith, mygeneration generation tool NHibernate template A variety of, generated mapping, structure, very redundant, for the complex domain will always have a variety of error mapping, most of the time only in a helpless situation to use, But the survey found that generative tools are often a beginner's favorite and don't feel much better.

Ajgenesis

Official address: http://ajgenesis.codeplex.com/

Ajgenesis is an open source project that generates a lot of stuff according to the template you define, supports language Java, JSP, ASP, vb.net, C #, PHP. The build contains entities, pages, solution and project files, store procedures, DDL scripts, and more.

Related Open source projects

Open Source Library has many, such as NHibernate contribution Project DLL2HBM, NHibernate mappingattributes, open source project Castle ActiveRecord, Fluent NHibernate and so on.

Where NHibernate mappingattributes and castle ActiveRecord are mapped using the attribute form in domain, the domain responsibility is completely polluted.

Fluent NHibernate uses the Fluent API as a form of mapping, and its API is still cumbersome, and its final effect is to generate very redundant XML files internally using your mapped fluent.

To write XML in a manual way

Found that more people like to write their own XML files manually, this is more flexible and convenient, I also particularly recommended here, on the one hand, familiar with the mapping skills, on the one hand added experience.

We only need to add the ability to write NHibernate configuration and map Smart hints for Microsoft Visual Studio 2010. Just find the configuration.xsd and nhibernate-mapping.xsd two files in the downloaded NHibernate package and copy them to C:\Program Files\Microsoft Visual Studio 10.0\xml\schemas directory.

Conclusion

Starting with the mapping chapter of NH anatomy, this article first outlines the mapping approach. According to the reaction situation inside the group, after I was divided into two sections began to introduce mapping, respectively from mapping mapping and conform actual combat two angles.

Mapping mapping: Describes the various mapping node mappings, so that you understand the various mapping, using manual XML method.

Conform combat: Using Orum thought to realize the mapping of domain.

I hope this article will be of some help to you.

Copyright NOTICE: This article for Bo Master http://www.zuiniusn.com original article, without Bo Master permission not reproduced.

NHibernate3 Anatomy: Mapping Overview of mapping articles

Related Article

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.