NHibernate Tour (20): Re-explore the use of Schemaexport tools

Source: Internet
Author: User
Tags generator

The contents of this section

Introduced

Example analysis

1. Tables and their constraints

2. Stored procedures, views

Conclusion

Introduced

In the last chapter we explored the use of the Schemaexport tool, knowing how to use the Schemaexport tools and schemaupdate tools to delete, create, and update database schemas using NHibernate persistence classes and mapping files. How does this specific analysis add some constraints to the table field? How do I build a stored procedure? How do I build a view? Use the Schemaexport tool to help you get it done.

Example Analysis 1. Table and its constraints

As we all know, the Schemaexport tool generates a database schema based on the mapping file, which makes it easy to generate database tables through class mapping in the mapping file. But this one we look at the mapping conditions, so I redefine two entities Categoryschema and Productschema, one-to-many relationships.

STEP1: Two entity persistence classes write code as follows:

public class CategorySchema
{
  public virtual Guid Id { get; set; }
  public virtual string Name { get; set; }
}
public class ProductSchema
{
  public virtual Guid Id { get; set; }
  public virtual string Name { get; set; }
  public virtual int UnitsOnStock { get; set; }
  public virtual CategorySchema CategorySchema { get; set; }
}

STEP2: Mapping for two entities, using the simplest way to write code as follows:

<?xml version="1.0" encoding="utf-8" ?>
          assembly="DomainModel" namespace="DomainModel">
 <class name="DomainModel.Entities.CategorySchema,DomainModel">
  <id name="Id">
   <generator class="guid"/>
  </id>
  <property name="Name"/>
 </class>

 <class name="DomainModel.Entities.ProductSchema,DomainModel">
  <id name="Id">
   <generator class="guid"/>
  </id>
  <property name="Name"/>
  <many-to-one name="CategorySchema"
     class="DomainModel.Entities.CategorySchema,DomainModel"/>
 </class>

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.