How to create reference tables using fluent nhibernate
- by Akk
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");
}
}