nHibernate Query

  • 3,118 views
Uploaded on

 

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,118
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
69
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. nHibernate Query
    Albert Kuo
  • 2. How nHibernation work?
    nHibernateQuery
    basic query
    Restriction
    String matcher
    Dynamic queries
    Subqueries
    Using Dynamic Institation
    Agenda
    2
  • 3. How nHibernation work?
    Utilize session to
    manipulate VOs
    Criteria
    Session
    tables
    VOs
    VOs
    VOs
    Configuration
    SessionFactory
    VOs
    3
  • 4. How nHibernation work? – cont.
    create
    update
    4
  • 5. How nHibernation work? – cont.
    delete
    find
    5
  • 6. nHibernate Query
    Criteria API
    Hibernate Query Language
    Object oriented querying
    Increase compile-time syntax-checking
    Easy to write
    Hard to read
    String-based querying
    Object-Oriented SQL
    Similar to SQL
    Speak in terms of objects
    Case sensitive
    Very flexible
    Zero compile-time syntax-checking
    6
  • 7. Using the ICriteriainterface:
    ICriteriacriteria = session.CreateCriteria(typeof(Cases));
    Generate SQL statement:
    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_
    nHibernate Query – basic query
    7
  • 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.
    nHibernate Query – Restriction
    8
  • 9. The like operator allows wildcard searches, where the wildcard symbols are % and _
    nHibernate Query – String matcher
    9
  • 10. It’s common for queries to be built programmatically by combining several optional query criteria depending on user input.
    nHibernate Query – Dynamic queries
    10
  • 11. 11
  • 12. nHibernate Query – Subqueries
    12
  • 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:
    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
    nHibernate Query – Using Dynamic Institation
    13
  • 14. Chapter 11. HQL: The Hibernate Query Language
    https://www.hibernate.org/hib_docs/nhibernate/html/queryhql.html
    NHibernate in Action
    http://www.manning.com/kuate/
    Reference
    14