NHiberate Many-To-Many sin tabla de combinación o claves externas

I have in herited a legacy database that doesn't have foreign keys on these 2 tables, and therefore not surprisingly, no join table.

If I'm not misataken creating a join table now is impossible since I can't create a foreign key on either of these tables, because both table have many records per BookingIds. Or am I wrong somehow?

BookingsTable
  ID - primarykey
  BookingId (this is what I need to join on)

BookingLocationsTable
  ID - primaryKey
  BookingId (this is how I would join)

I would like to create a many to many relationship between these to tables in fluent nHibernate.

Es esto imposible?

Would I better off trying do a simple query with a join?

If so I might need to abandon hibernate / nhibernate at all because the these tables are vital to the domain, and perhaps there will be more examples of this.

Or perhaps I need to restructure the database / tables some how to use nHibernate?

preguntado el 01 de febrero de 12 a las 14:02

BookingsTable Tiene uno BookingId y BookingLocationsTable has one, too and you want to relate entities from this two tables when BookingId is equal? If so, I'll rather say there are two one-to-many's instead of many-to-many. Let me know if that's the case - it is possible to write a mapping like this. -

@NOtherDev you know I think you're right. In general it seems like a many to many is logically the same thing as 2 1 to manys? -

@NOtherDev even if this is 2 one-to-many relationship, I still can't use nHibernate for this because I cannot create a foreign key on the bookingId column of either tables because it would require a unique key of the one side of the relationship, which I can't create. -

1 Respuestas

After some reflection and discussion, I realise that there is actually no salvagable relationship between these 2 tables.

I am new to this type of ORM so had assumed that I needed some sort of relationship between the tables to do the equivalent of a join.

After some research I have found that I can use linq to nHibernate, HQL, or even db native SQL to do what I need to do.

Upward an onward :)

Respondido 02 Feb 12, 16:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.