के साथ पूछताछ मैं NHibernate के लिए नया हूं और मैं अपने डेटा से पूछताछ करने के तरीके सीखने की कोशिश कर रहा हूं।NHibernate
नीचे कॉन्फ़िगरेशन xml है। केवल नुस्खा दिखाया गया है।
मैं दर्ज किए गए कीवर्ड से व्यंजनों से व्यंजनों से पूछताछ करना चाहता हूं और घटक नाम से सामग्री भी प्राप्त करना चाहता हूं।
तो उदाहरण के लिए आप "पास्ता शराब" दर्ज कर सकते हैं।
यही मैंने कोशिश की है लेकिन मुझे एक त्रुटि देता है।
hql = "from Recipe r " +
"left join r.Images " +
"inner join r.User " +
"inner join r.Ingredients i " +
"where i.IngredientName Like '%pasta%' OR i.IngredientName Like '%wine%' OR r.RecipeTitle Like '%pasta' OR r.RecipeTitle Like '%wine%'";
मैं संग्रह को भी लोड करना चाहता हूं।
क्या मैं सही पूछताछ के बारे में जा रहा हूं ?? मुझे अपने खोज मानदंडों से क्वेरी स्ट्रिंग बनाने में सक्षम होना चाहिए। एसक्यूएल में यह आसान फॉर्म होगा।
मैल्कम
<class name="Recipe" table="Recipes" xmlns="urn:nhibernate-mapping-2.2">
<id name="RecipeID" type="Int32" column="RecipeID">
<generator class="identity" />
</id>
<property name="RecipeTitle" type="String">
<column name="RecipeTitle" />
</property>
<property name="Completed" type="Boolean">
<column name="Completed" />
</property>
<property name="ModifiedOn" type="DateTime">
<column name="ModifiedOn" />
</property>
<property name="Rating" type="Double">
<column name="Rating" />
</property>
<property name="PrepTime" type="Int32">
<column name="PrepTime" />
</property>
<property name="CookTime" type="Int32">
<column name="CookTime" />
</property>
<property name="Method" type="String">
<column name="Method" />
</property>
<bag name="Images" inverse="true" cascade="all">
<key column="RecipeID" />
<one-to-many class="OurRecipes.Domain.RecipeImage, OurRecipes.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bag>
<many-to-one name="Category" column="CategoryID" />
<bag name="Comments" inverse="true" cascade="all">
<key column="RecipeID" />
<one-to-many class="OurRecipes.Domain.Comment, OurRecipes.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bag>
<many-to-one name="User" column="EnteredByID" />
<bag name="Ingredients" inverse="true" cascade="all">
<key column="RecipeID" />
<one-to-many class="OurRecipes.Domain.Ingredient, OurRecipes.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bag>
</class>
इस समस्या को हल करने के लिए, आप DistinctRootEntityResultTransformer –
प्राप्त कर सकते हैं आप FetchMode.Join के बजाय FetchMode.Join का उपयोग क्यों करेंगे यदि आप वास्तव में बाल वस्तुओं का उपयोग करने का इरादा रखते हैं? –
मुझे नहीं लगता कि जब आप कीवर्ड को हार्ड कोड करते हैं तो यह गतिशील कैसे होता है।यदि आप रिक्त स्थान से अलग शब्दों की एक स्ट्रिंग देते हैं तो आप कैसे पूछेंगे ??? – Malcolm