Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

nHibernate Query

3,693 views

Published on

Published in: Technology, Business
  • Be the first to comment

nHibernate Query

  1. 1. nHibernate Query<br />Albert Kuo<br />
  2. 2. How nHibernation work?<br />nHibernateQuery<br />basic query<br />Restriction<br />String matcher<br />Dynamic queries<br />Subqueries<br />Using Dynamic Institation<br />Agenda<br />2<br />
  3. 3. How nHibernation work?<br />Utilize session to <br />manipulate VOs<br />Criteria<br />Session<br />tables<br />VOs<br />VOs<br />VOs<br />Configuration<br />SessionFactory<br />VOs<br />3<br />
  4. 4. How nHibernation work? – cont.<br />create<br />update<br />4<br />
  5. 5. How nHibernation work? – cont.<br />delete<br />find<br />5<br />
  6. 6. nHibernate Query<br />Criteria API<br />Hibernate Query Language<br />Object oriented querying<br />Increase compile-time syntax-checking<br />Easy to write<br />Hard to read<br />String-based querying<br />Object-Oriented SQL<br />Similar to SQL<br />Speak in terms of objects<br />Case sensitive<br />Very flexible<br />Zero compile-time syntax-checking<br />6<br />
  7. 7. Using the ICriteriainterface:<br />ICriteriacriteria = session.CreateCriteria(typeof(Cases));<br />Generate SQL statement:<br />select cases0_.caseId as caseId0_, cases0_.caseDesc as caseDesc0_, cases0_.caseTime as caseTime0_, cases0_.caseType as caseType0_, cases0_.caseAddr as caseAddr0_, cases0_.reporterStaff as reporter6_0_, cases0_.reporterPhone as reporter7_0_, cases0_.reporterAddr as reporter8_0_, cases0_.receiverStaff as receiver9_0_, cases0_.receiveTime as receive10_0_, cases0_.caseState as caseState0_, cases0_.updtDate as updtDate0_, cases0_.county as county0_, cases0_.town as town0_, cases0_.caseClass as caseClass0_ from Cases cases0_<br />nHibernate Query – basic query<br />7<br />
  8. 8. You usually don’t want to retrieve all instances of a class when you run a query. Instead, you want to express some constraints on the property values of your objects, so only a subset of objects is retrieved. This is called restriction.<br />nHibernate Query – Restriction<br />8<br />
  9. 9. The like operator allows wildcard searches, where the wildcard symbols are % and _<br />nHibernate Query – String matcher<br />9<br />
  10. 10. It’s common for queries to be built programmatically by combining several optional query criteria depending on user input.<br />nHibernate Query – Dynamic queries<br />10<br />
  11. 11. 11<br />
  12. 12. nHibernate Query – Subqueries<br />12<br />
  13. 13. If you find working with arrays of values a little cumbersome, NHibernate let’s you use dynamic instantiation and define a class to represent each row of results. You can do this using the HQL select new construct:<br />The custom ItemRow class doesn’t have to be a persistent class that has its own mapping file. But in order for NHibernate to “see” it, you need to import it using<br />nHibernate Query – Using Dynamic Institation<br />13<br />
  14. 14. Chapter 11. HQL: The Hibernate Query Language<br />https://www.hibernate.org/hib_docs/nhibernate/html/queryhql.html<br />NHibernate in Action<br />http://www.manning.com/kuate/<br />Reference<br />14<br />

×