Asp. Net large project practice (4)-Save and query our business objects with nhib.pdf

Source: Internet
Author: User

There are not many information about nhib.pdf. in the Net project, there will be fewer practical materials, and many detours have been taken when we started using nhib.pdf. Now we feel that we can properly apply nhib.pdf to the project. I would like to thank my colleague 1-2-3 for his efforts to solve many technical issues related to the NHibernate application. I also want to thank Li yongjing for his article navigation in the NHibernate series, saving me trouble reading the English documents at the early stage of the entry. Thanks to the two articles, it seems that NHibernate does not matter to me... khan
Note: For more information. there are a lot of ORM tools available under. Net, but I personally think nhib.pdf is currently. net is the most powerful and best-to-Use ORM tool. I don't want to provoke it here.. Net ORM framework competition. If you want to compete, we hope that you will talk about the actual application in the project.No prerequisiteBored. At least in my project, it is just because of nhib.pdf that I can compare OO to create my business domain objects. It seems to be closer to the so-called real object relationship ing in the legend ....

  1. Similarly, in accordance with international practices, we should establish a unified general database access interface code

       namespace Demo.HIS.FrameWork.Repository
    {
    public interface IRepository<T> where T:Entity
    {
    T Load(string id);
    T Get(string id);
    IList<T> GetAll();
    void SaveOrUpdate(T entity);
    void Update(T entity);
    void Delete(string id);
    void PhysicsDelete(string id);
    }
    }

    A. You should use the names of these interface methods to guess their meanings? What to get an object, save the object, delete the object, and get a List...
    B. public interface IRepository <T> where T: Entity indicates that the generic object T can only be an object inherited from the Entity base class. Do you still remember Entity? Asp. net large project practice (3)-Object Modeling in the business field as mentioned in this Article, Entity is the base class of all business objects in the system that can be persisted to the database, in this way, you can avoid passing the type of a cat or a dog to me and ask me to Save, Delete ....
    C. The names of Load and Get are related to nhib.pdf. In the future, we will talk about the difference between "Hibernate Get Load"
    D. Delete and PhysicsDelete. in the previous article, we talked about logical deletion by default in our system. Therefore, physical deletion is a special name for "abnormal" objects.
    E. some people are not interested in the simple design of the interface... don't worry, take a look at the typical application scenarios such as paging, sorting, multi-condition combined query, and multi-Table query .. there is a picture with the truth:

  2. With the IRepository interface, we can write the specific implementation for this interface, because we use nhib.pdf to implement this class code.

       Namespace Demo. HIS. FrameWork. Repository. Nhb
    {
    Public class RepositoryNhbImpl <T>: IRepository <T> where T: Entity
    {

    # Region IRepository <T> Member

    Public T Load (string id)
    {
    Throw new NotImplementedException ();
    }

    Public T Get (string id)
    {
    Throw new NotImplementedException ();
    }

    Public IList <T> GetAll ()
    {
    Throw new NotImplementedException ();
    }

    Public void SaveOrUpdate (T entity)
    {
    Throw new NotImplementedException ();
    }

    Public void Update (T entity)
    {
    Throw new NotImplementedException ();
    }

    Public void Delete (string id)
    {
    Throw new NotImplementedException ();
    }

    Public void PhysicsDelete (string id)
    {
    Throw new NotImplementedException ();
    }

    # Endregion
    }
    }

     

    If you want to use Linq to access the database, create a class named "public class RepositoryLinqImpl <T>: IRepository <T> where T: Entity, however, if this is the case, you have no need to continue reading it, because the following basics are nothing to do with Linq .....

  3. Insert a sentence. The following content involves more technical details about NHibernate. We recommend that you navigate the series of NHibernate articles of Li yongjing's eldest brother to the next article. Otherwise, it is not easy to understand, however, I try to write a little more details, at least to make everyone understand it. After writing it, I will also post the source code for your reference. The source code will be downloaded in the next article.
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.