Fluent Nhibernate many-to-many where table has multiple columns
I am trying to to map a many to many relationship using Fluent NHibernate.
I have a table User and a second table Orga开发者_StackOverflow中文版nization. The association table is UserOrganization which contains the UserId and OrganizationId. The UserOrganization table also contains a few other fields (YearBegan, YearEnd).
How would I go ahead and map those using fluent mapping.
Thanks
You should probably make UserOrganization its own entity that contains those fields. That also gives you more flexibility in terms of cascading updates and deletes.
public class UserOrganization {
public virtual User User { get; set; }
public virtual Organization Organization { get; set; }
public virtual DateTime YearBegan { get; set; }
public virtual DateTime YearEnd { get; set; }
}
精彩评论