My feelings about nhib.pdf (1): misunderstandings about delayed Loading Methods

Source: Internet
Author: User
Tags emit

My feelings about nhib.pdf (1): misunderstandings about delayed Loading Methods

By Jeffrey Zhao, 14390 visits, favorites, Edit

Nhib.pdf is the most famous ORM framework on the. NET platform. Although it was born from Hibernate on the Java platform, it seems that it is almost a native product on the. NET platform: it has its ownCommunityHas its own users, business support, and independent expansion using the C # feature. Unlike Lucene. net, it shows a strong Java flavor at a glance, Java Naming methods, and so on. I have not used nhib.pdf for a long time, and the complexity of nhib.pdf also determines that I cannot be as easy as I know about LINQ to SQL. However, after using it for a while, I still have some experience with it. There are joys, misunderstandings, and complaints.

These articlesArticleI don't want to talk about the advantages of nhiberante, because its advantages are too obvious. If you do not consider the commercial framework like telerik ORM (because I have never used it, I don't know it at all ),. on the Net platform, open-source and free ORM tools are almost no opponent of nhib.pdf: it is indeed easy to use, get started very quickly, and some functions are very meticulous (I will talk about it later ), however, the soul of the ORM tool "mapping capability" is not flattering. Some time ago, I also briefly learned about Microsoft's new Entity Framework. Although it also adheres to Microsoft's consistent ease of use (such as powerful LINQ support), it has also improved its mapping capability, however, it is far inferior to nhib.pdf in terms of functions and some details. After all, nhib.pdf has experienced many years of development and has taken countermeasures in almost all situations. If the latency is not met, select or join is used to obtain data and whether conditions are attached when the set is loaded. In addition, I am satisfied with the scalability of Nhibernate interceptor, but I have the opportunity to discuss it in detail.

In short, nhib.pdf is my most satisfactory ORM framework.

Now enter the body content. First of all, I want to talk about my misunderstanding about the implementation of nhib.pdf. This misunderstanding has caused me to complain about nhib.pdf errors all the time, I have repeatedly accused nhib.pdf of errors in several articles. I have corrected the mistakes and hope they will not cause too many problems.

This misunderstanding is that I have always thought that nhib.pdf uses a simple method of delayed loading. For example, there is an object:

 
Public classArticle{Public Virtual intArticleID {Get;Set;}Public Virtual stringTagnames {Get;Set;}}

During Delayed loading, I always thought that Nhibernate only generates a sub-class of article through emit, and then overwrites the attributes into simple read/write, for example:

Public classArticle $ lazyproxy:Article{Private stringM_tagnames;Public override stringTagnames {Get{Return this. M_tagnames ;}Set{This. M_tagnames =Value;}}}

The problem is that the original logic of the tagnames attribute is lost. For DTO models with lost blood, this naturally does not matter because these attributes have no internal logic. However, I am used to using the domain-driven design (DDD) method to model products, so these attributes may have some business logic. For example, changing other States of an object, synchronizing data to other fields, or triggering events. Therefore, the impact of missing attribute logic on me is fatal, which means that I have to "take care" of nhib.pdf features for programming, when modeling, we began to consider the persistence logic as a major problem in DDD practices-although software development is not idealistic and trade-offs are normal, if nhiberante can only cope with the loss of DTO models, so it is sorry for its industry reputation.

It is a pity that Nhibernate didn't jump here -- so it may be better to say "fortunately" -- it uses a delayed proxy statement that maintains the original business logic:

 
Public classArticlelazyproxy:Article{Public override stringTagnames {Get{VaRTagnames =...// Load dataBase. Tagnames = tagnames;Return Base. Tagnames ;}Set{Base. Tagnames =Value;}}}

Of course, this is a reverse example from "Test Results". The actual practice of nhiberante should not be that simple. If you pay attention to my article, you will find that this is the most ideal implementation method of latency proxy that I have previously proposed. It is also the practice I use in the eazy class library. After implementing the basic functions of eazy, I was slightly complacent because it met my requirements. Who knows this has long been taken down by Nhibernate. I was shocked when I tried this result last night, not because of the strength of nhib.pdf (because it shouldn't have made this low-level mistake ), it's because I don't understand why I used to think about nhib.pdf easily? I think I have complained about this in many articles. After the experiment yesterday, I immediately modified all the nonsense I could think. Sorry.

Ah, do not load B, and load B to be hacked.

Related Articles
    • My feelings about nhib.pdf (1): misunderstandings about delayed Loading Methods
    • My feelings about nhib.pdf (2): Why is virtual everywhere?
    • My feelings about nhib.pdf (3): some embarrassing collections support
    • My feelings for nhibator (4): an amazing interceptor mechanism

Nhib.pdf is. the most famous ORM framework on the net platform, although originated from Hibernate on the Java platform, it is almost an external. NET platform native products: have their own communities, have their own users, have their own business support, and have independent extensions using the C # feature. Unlike Lucene. net, it shows a strong Java flavor at a glance, Java Naming methods, and so on. I have not used nhib.pdf for a long time, and the complexity of nhib.pdf also determines that I cannot be as easy as I know about LINQ to SQL. However, after using it for a while, I still have some experience with it. There are joys, misunderstandings, and complaints.

In these articles, I am not going to talk about the advantages of nhiberante, because its advantages are too obvious. If you do not consider the commercial framework like telerik ORM (because I have never used it, I don't know it at all ),. on the Net platform, open-source and free ORM tools are almost no opponent of nhib.pdf: it is indeed easy to use, get started very quickly, and some functions are very meticulous (I will talk about it later ), however, the soul of the ORM tool "mapping capability" is not flattering. Some time ago, I also briefly learned about Microsoft's new Entity Framework. Although it also adheres to Microsoft's consistent ease of use (such as powerful LINQ support), it has also improved its mapping capability, however, it is far inferior to nhib.pdf in terms of functions and some details. After all, nhib.pdf has experienced many years of development and has taken countermeasures in almost all situations. If the latency is not met, select or join is used to obtain data and whether conditions are attached when the set is loaded. In addition, I am satisfied with the scalability of Nhibernate interceptor, but I have the opportunity to discuss it in detail.

In short, nhib.pdf is my most satisfactory ORM framework.

Now enter the body content. First of all, I want to talk about my misunderstanding about the implementation of nhib.pdf. This misunderstanding has caused me to complain about nhib.pdf errors all the time, I have repeatedly accused nhib.pdf of errors in several articles. I have corrected the mistakes and hope they will not cause too many problems.

This misunderstanding is that I have always thought that nhib.pdf uses a simple method of delayed loading. For example, there is an object:

Public classArticle{Public Virtual intArticleID {Get;Set;}Public Virtual stringTagnames {Get;Set;}}

During Delayed loading, I always thought that Nhibernate only generates a sub-class of article through emit, and then overwrites the attributes into simple read/write, for example:

Public classArticle $ lazyproxy:Article{Private stringM_tagnames;Public override stringTagnames {Get{Return this. M_tagnames ;}Set{This. M_tagnames =Value;}}}

The problem is that the original logic of the tagnames attribute is lost. For DTO models with lost blood, this naturally does not matter because these attributes have no internal logic. However, I am used to using the domain-driven design (DDD) method to model products, so these attributes may have some business logic. For example, changing other States of an object, synchronizing data to other fields, or triggering events. Therefore, the impact of missing attribute logic on me is fatal, which means that I have to "take care" of nhib.pdf features for programming, when modeling, we began to consider the persistence logic as a major problem in DDD practices-although software development is not idealistic and trade-offs are normal, if nhiberante can only cope with the loss of DTO models, so it is sorry for its industry reputation.

It is a pity that Nhibernate didn't jump here -- so it may be better to say "fortunately" -- it uses a delayed proxy statement that maintains the original business logic:

 
Public classArticlelazyproxy:Article{Public override stringTagnames {Get{VaRTagnames =...// Load dataBase. Tagnames = tagnames;Return Base. Tagnames ;}Set{Base. Tagnames =Value;}}}

Of course, this is a reverse example from "Test Results". The actual practice of nhiberante should not be that simple. If you pay attention to my article, you will find that this is the most ideal implementation method of latency proxy that I have previously proposed. It is also the practice I use in the eazy class library. After implementing the basic functions of eazy, I was slightly complacent because it met my requirements. Who knows this has long been taken down by Nhibernate. I was shocked when I tried this result last night, not because of the strength of nhib.pdf (because it shouldn't have made this low-level mistake ), it's because I don't understand why I used to think about nhib.pdf easily? I think I have complained about this in many articles. After the experiment yesterday, I immediately modified all the nonsense I could think. Sorry.

Ah, do not load B, and load B to be hacked.

Related Articles
    • My feelings about nhib.pdf (1): misunderstandings about delayed Loading Methods
    • My feelings about nhib.pdf (2): Why is virtual everywhere?
    • My feelings about nhib.pdf (3): some embarrassing collections support
    • My feelings for nhibator (4): an amazing interceptor mechanism

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.