Spring.net+nhibenate+asp.net MVC +EXTJS Series 3----data access layer

Source: Internet
Author: User

In the previous article, we built the entire solution project and built the database to complete the entity classes and nhibernate mapping files. In this article, you will define the data access interface and implement the interface using NHibernate. Use spring.net to configure DAO. and unit Test it.

The data access layer, like the PetShop framework, is divided into data access interfaces and implementations, but the data access implementation is much clearer and more obvious than the nhibernate itself, so it's not for multiple databases, But to nhibernate the plug, even if one day found that due to some problems, such as performance problems, you can implement the Idal interface, but not to the business layer caused a larger change.

Here, in fact, we still do not know what the front desk really needs, so we simply realize the deletion of the entity to check it. When other functions are needed, the interface and implementation are perfected.

Directcenter.idal is not dependent on spring or nhibernate, just add the project reference Directcenter.model. To the user, add the interface IUserDao.cs

IUserDao.cs
using System.Collections;
using DirectCenter.Model;
namespace DirectCenter.IDAL
{
  public interface IUserDao
  {
    User FindById(string userId);
    void Delete(User user);
    User Save(User user);
    User SaveOrUpdate(User user);
  }
}

Again, we add Icompanydao and Idepartmentdao.

Next, we implement the data interface just now, add the project references to Directcenter.idal and Directcenter.model in the Directcenter.dal project, Then add the reference Spring.data.nhibernate20,spring.data,spring.core (below lib/spring.net).

One way to do this is to use NHibernate directly to complete data access:

UserDao.cs
  public User Save(User user)
    {
     //通过一种方式获取Session
      Session session = SessionFactory.OpenSession();
      session.Save(user);
    }

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.