I have the following code:
public class Hotel
{
public int ID
{
get;set
}
public IList<Photo> Photos
{
get;set;
}
//...other code
}
public class Photo
{
public int ID
{
get;set;
}
//...other fields
}
In the database, I have the following tables:
Photo: ID, Url, //.. other fields
HotelPhoto:ID, PhotoID, HotelID
Hotel:ID, Location, //..other fields
with relationships between Hotel <--> HotelPhoto and HotelPhoto <--> Photo.
My question is: Can I configure somehow a mapping between Hotel class and Hotel table to get a list of Photo without creating a new class HotelPhoto? ( I want a list of photos, not a list of HotelPhoto from which to get my photos).
Somehow I want to access the Photo table from the Hotel class without any class HotelPhoto, knowing that the table HotelPhoto contains only the IDs of Hotel and Photo table.
Thanks in advance,
Tamash
You can use a
many-to-many-mapping e.g.:The hotel mapping file, should contain sth. like this:
For the photo mapping file you can use sth. like this:
Note, that the mapping is not tested and assumes that a Photo has a list of hotels (otherwise your db-schema does not make sense for me).
You can find the documentation here. http://nhibernate.info/doc/nh/en/index.html#collections-ofvalues