You can't. You need to explicitly model and map that mapping table now.
fluentNhibernate: how to add an extra attribute to a relationship (aka relationship attribute)
-
29-06-2022 - |
Domanda
I have two entities, Albums and Photos, with a many-to-many relationship between then. Its all working fine. What I want is to add an relationship attribute i.e. an extra attribute to the mapping besides album_id and photo_id, for example the datetime the photo was added or an attribute that says if the photo is visible or not on that album.
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; }
}
The current mapping goes like this:
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");
}
}
Soluzione
Altri suggerimenti
I've something like this:
HasManyToMany<EnterpriseRelation>(x => x.SharedIn)
.Table("SharedDocs")
.ChildWhere("State=" + StateId.Accepted) // this filter out all relation that aren't accepted
.ParentKeyColumn("DocId")
.ChildKeyColumn("RelationId");
StateId.Accepted
is a costant so no problem, but i don't think you can do more (with this).
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow