Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I have the following code:
public class Hotel
{
    public int ID
    {
     get;set
    }

    public IList<photo> Photos
    {
      get;set;
    }
//...other code
}

</photo>


and

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 define a mapping between Hotel and 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).

Thanks in advance,
Tamash
Posted

1 solution

Yes, itz possible. I'm not much familiar with NHibernate; but with the related ORMs like LInQ, etc. The customized mapping is achievable by writing our own Convert methods as

C#
public void List<photo> ConvertEntityHotelToPhoto(Hotel hotel)
{
    List<photo> retPhoto = new List<photo>();
    foreach(Photo photo in hotel.Photos)
    {
       retPhoto.Add(photo);
    }
    return retPhoto;
}</photo></photo></photo>
 
Share this answer
 
Comments
tamash_ionut 30-Aug-11 6:36am    
Well that is not what I want. I dont want to write extra code for this functionality. In Entity Framework, a situation like :
Hotel <--> HotelPhoto(HotelID, PhotoID) <--> Photo automatically figures out that hotel has may photos and does not create a class HotelPhoto.
My question is if I can have a similar behaviour without having to write HotelPhoto class, by configuring somehow the mapping file?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900