How to create reference tables using fluent nhibernate
        Posted  
        
            by Akk
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Akk
        
        
        
        Published on 2010-05-22T07:45:04Z
        Indexed on 
            2010/05/22
            8:30 UTC
        
        
        Read the original article
        Hit count: 212
        
fluent-nhibernate
How can i create a 3 table schema from the following model classes.
public class Product
{
  public int Id {get; set;}
  public string Name {get; set;}
  public IList<Photo> Photos {get; set;}
}
public class Photo
{
  public int Id {get; set;}
  public string Path {get; set;}
}
I want to create the following table structure in the database:
Product
-------
Id
Name
ProductPhotos
-------------
ProductId (FK Products.Id)
PhotoId (FK Photos.Id)
Photos
------
Id
Path
How i can express the above Database Schema using Fluent NHibernate? I could only manage the following the Mapping but this does not get me the 3rd Photo ref table.
public class ProductMap : ClassMap<Product>
    {
        public CityMap()
        {  
            Id(x => x.Id);
            Map(x => x.Name);            
            Table("Products");
            HasMany(x => x.Photos).Table("ProductPhotos").KeyColumn("ProductId");
        }
    }
© Stack Overflow or respective owner