I have 2 entities that are playing nice together when I am pulling data out of the database, but now that I am trying to save something I am getting a strange error and elimination isn’t helping me track down the cause:

Booking
public class Booking
{
public virtual int Id { get; set; }
public virtual Int32 bookingID { get; set; }
}
Booking Location
public class BookingLocation
{
public virtual int Id { get; set; }
public virtual Int32 bookingID { get; set; }
public virtual Int32 locationID { get; set; }
public virtual DateTime startDateTime { get; set; }
public virtual DateTime endDateTime { get; set; }
}
Booking Mapping
public class BookingMap : ClassMap<Booking>
{
public BookingMap()
{
Table("Bookings");
Id(x => x.Id).Column("ID");
Map(x => x.bookingID).Column("BookingID");
HasMany(x => x.BookingLocations)
.KeyColumn("BookingID")
.Not.LazyLoad().Cascade.All();
}
}
BookLocation Mapping
public class BookingLocationMap : ClassMap<BookingLocation>
{
public BookingLocationMap()
{
Table("Bookings_Locations");
Id(x => x.Id).Column("ID");
Map(x => x.bookingID).Column("BookingID");
Map(x => x.locationID).Column("LID");
Map(x => x.startDateTime).Column("startdatetime");
Map(x => x.endDateTime).Column("enddatetime");
References(x => x.Booking)
.Column("BookingID")
.Not.LazyLoad().Nullable()
.Cascade.All();
}
}
Any ideas?
You are trying to map the same column twice (
BookingId):If you need to reference the field
BookingIdyou can just use your many to one (References)Booking.BookingIdso your mapping would become:Example
I have read only access to my collections so I use the following methods to add and remove items from this collection: