NHibernate Tour (14): Explore the use of views in NHibernate

Source: Internet
Author: User

The contents of this section

Introduced

1. Persistence class

2. Mapping file

3. Test

Conclusion

Introduced

In database operations, in addition to table operations, as well as views, stored procedures, and other operations, this article and the next article to learn about these things. In this article we'll learn how to use views in nhibernate. First, we set up a database named Viewcustomer view, select CustomerID, Firstname, Lastname, OrderId, OrderDate items.

Let's write the Persistence class and mapping for this view in turn.

1. Persistence class

Like the tables in the persisted database, we need to persist the view to define each property in the views, because the view is read-only, so here we simply set the setter of the property to private access. The following are specific practices:

Create a new CustomerView.cs class in the Entities folder of the project Domainmodel layer, writing the following code:

namespace DomainModel.Entities
{
  public class CustomerView
  {
    public virtual int CustomerId { get; private set; }
    public virtual string Firstname { get; private set; }
    public virtual string Lastname { get; private set; }
    public virtual int OrderId { get; private set; }
    public virtual DateTime OrderDate { get; private set; }
  }
}

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.