我有两个实体,相册和照片,它们之间存在多对多关系。它一切正常。我想要的是添加一个关系属性,即除了album_id 和photo_id 之外的映射的额外属性,例如添加照片的日期时间或说明照片在该相册上是否可见的属性。
public class Photo
{ public virtual int Id { get; set; }
public virtual string Title { get; set; }
public virtual ICollection<Album> Albums { get; set; }
}
public class Album
{
public virtual int Id {get;set;}
public virtual string Title {get;set;}
public virtual ICollection<Photo> Photos { get; set; }
}
当前的映射是这样的:
public class PhotosMap : ClassMap<Photo>
{
public PhotosMap()
{
Id(x => x.Id);
Map(x => x.Title);
HasManyToMany<Album>(x => x.Albums).Not.LazyLoad().Table("album_photos");
Table("photos");
}
}
public class AlbumsMap : ClassMap<Album>
{
public AlbumsMap()
{
Id(x => x.Id);
Map(x => x.Title);
HasManyToMany<Photo>(x => x.Photos).Inverse().Not.LazyLoad().Table("album_photos");
Table("album");
}
}