views:

48

answers:

1

I am new to NHibernate. I am using following property elements in my hbm file...

<property name="CountryId" length="4" />
<property name="CountryForCustomer"
              formula="(SELECT *
                            FROM SystemCountry  
                            WHERE SystemCountry.CountryId = CountryId)" />

Here I am trying to get Country details from the CountryId that I am having in an other table.

Property "CountryForCustomer" is of custom type "SystemCountry".

But this query in formula is not working.. So someone please help me solving this issue.

Thanks in Advance....

+1  A: 

Should it not be

SELECT SystemCountry.Country FROM SystemCountry WHERE...

as the * would return multiple columns from the query

edit If you want to return the whole object back then the property element is not your friend here. What you want to do is look at the many-to-one element, note that this is just one way to do this.

<many-to-one name="CmsTemplate" column="TemplateId" ..

e.g. here or here

Rippo
ok, got your point.. But I want whole object of Country to use and not only one column value.. so how to achive that using hbm file mapping..?
Nikhil Thaker
many-to-one is definitly the solution here.
Stefan Steinegger
Now this solution is working but there is an issue.... When I initially inserting data or updating the data(using SaveorUpdate method of NHibernate), it do not bring the associated data with "many-to-one" element as I have set the "insert" and "update" attributes to false as keeping them true gives the error -> IndexOutOfRangeException -> "Invalid index 52 for this SqlParameterCollection with Count=52." So how to move forward from here..?
Nikhil Thaker
This is an entirely different question. Add a `new` question providing your mapping and poco classes. Then we can help more.
Rippo