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;}
}
pub开发者_如何学编程lic 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 ProductMap()
{
Id(x => x.Id);
Map(x => x.Name);
Table("Products");
HasMany(x => x.Photos).Table("ProductPhotos").KeyColumn("ProductId");
}
}
You have to create a classmap for the photo entity as well.
精彩评论