开发者

How to create reference tables using fluent nhibernate

开发者 https://www.devze.com 2022-12-31 12:17 出处:网络
How can i create a 3 table schema from the following model classes. public class Product { public int Id {get; set;}

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消