I think by default NHibernate will not load the Street object if you access
the Street.Id property.
So, you don't need the other Id property at all.

Also, if you want to assign a new Street property using the Id you can do
something like:

var newStreet = session.Load<Street>(newStreetId);
house.Street = newStreet;


The  Load() method will not query the DB unless you try to access other
properties than the Id. This is NHibernate preferred Object Oriented way of
doing this kind of "Id" operation.



*Mohamed Meligy
*Readify | Senior Developer

M:+61 451 835006 | W: readify.net
[image: Description: Description: Description: Description:
rss_16]<http://gurustop.net>
[image: Description: Description: Description: Description:
cid:[email protected]]
<http://www.linkedin.com/in/meligy>  [image:
Description: Description: Description: Description:
cid:[email protected]] <http://twitter.com/meligy>
 
<http://www.greatplacetowork.com.au/best/best-companies-australia.php><http://www.readify.net/AboutUs/NewsItem.aspx?id=10>



On Sat, Feb 19, 2011 at 9:12 AM, azemerov <[email protected]> wrote:

> Hi,
> I have a problem. Probably it is against traditional ORM approach, but
> anyway, I want to have both object reference (mapped as many-to-one)
> and reference key (mapped as property) be presented in my class.
> If I do something like
>
> public class Street
>  {
>    public virtual string   Id      { get; set; }
>  }
>
> public class House
>  {
>    public virtual string   Id      { get; set; }
>    public virtual string Street_Id { get; set; }
>    public virtual Street Street { get; set; }
>  }
>
> <class name="House" table ="HOUSE">
>    <id name="Id" column="ID">
>      <!-- generator class="guid" / -->
>    </id>
>    <property name="Street_Id" column ="STREET_ID" />
>
>    <many-to-one name="Street"
>                 column="STREET_ID"
>                 class="Street"
>                 cascade="none"
>                 fetch="join"
>                 />
>  </class>
>
> I get an IndexOutOfRangeException "Invalid index 2 for this
> OracleParameterCollection with Count=2." when new House object is
> saved.
>
> As I understand, it is result of double mapping of STREET_ID column.
>
> I want to see some workaround for this problem. My goal is to be able
> to access Street object directly from House in one scenario and in
> different scenario avoiding unnecessary loading of Street object get
> it's PK using referencing House object.
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to