Dynamic model in Nhibernate
I use Dynamic model in Nhibernate. Like this :
<class entity-name="Customer">
    <id name="id"
        type="long"
        column="ID">
        <generator class="sequence"/>
    </id开发者_开发知识库>
    <property name="name"
        column="NAME"
        type="string"/>
    <property name="address"
        column="ADDRESS"
        type="string"/>
    <many-to-one name="organization"
        column="ORGANIZATION_ID"
        class="Organization"/>
    <bag name="orders"
        inverse="true"
        lazy="false"
        cascade="all">
        <key column="CUSTOMER_ID"/>
        <one-to-many class="Order"/>
    </bag>
</class>
I use HQL for queries. I don't want perform select * all time. How can I say to Nhibernate which fields return . But I need the result in Idictionary where key is name from HBM thanks .
Have you tried something like this:
IQuery CustomerQuery = session.CreateQuery("select Name from TABLE where Id= :id")
                              .SetInt32("id", 1983056);
IList result = CustomerQuery.List();
So above I restrict the number of columns retrieved and will retrieve only 1 row where the Id matches.
The concept is called 'Projection'. Good luck!
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论