views:

32

answers:

1

I am stuck with a legacy database involving composite keys and there is no room to modify the db.

The problem seems to be that one part of the key is also used for each foreign key. So if I have tables A and B like this:

A

  • company (PK)
  • aId (PK)
  • someMoreInfo

B

  • company (PK, FK)
  • bId (PK)
  • aId (FK)
  • someOtherInfo

The company field in table B is PK for table B and used for ther FK to table A. All the things I tried lead me to Repeated column in mapping exceptions.

So this is not a 'how do I' question (well, if you have a solution - go ahead I'd consider myself lucky if this is just my imagination and there is no real problem…) but a 'do you feel this is right' question.

  • could it be possible to acces a db like this using nhibernate (well, apart from mapping all tables 1:1 without references)
  • do you feel it is a good idea?
  • what are the alternatives given my circumstances (i.e. Are any O/R-Mappers good at this)?

BTW: This is the same problem, and one of my complex scenarios is here.

A: 

I don't know how to solve the particular foreign-key-overlaps-primary-key issue you have, but I will say of the ORMs I've tried, NH is the most likely to be compatible with your legacy schema; in fact, it's one of NH's biggest design goals. So I'd say NH is right, and you're more likely to find an answer in it than you are with most other ORMs.

Isaac Cambron
Thanks, this at least gives me "some hope"
Nils