I do have giant Oracle Database which contain more than 1000 tables. And some of them does not have PK(Primary Key). I want to implement Nhibernate between C# and Oracle Database but it does not let me allow to do mapping because of primary Key. Is there any solution for this? please help me out for this problem.
-
If you expect a useful answer, I think you should provide some more information: how does your DB look. What code did you try already? – Kris Feb 22 '16 at 13:44
-
I have a oracle database that does not have primary key. I have been trying to add Nhibernate framework but it does not allow me. I tried to do that but I got error with mapping files. it is showing me that table should contain primary key. I don't know how to do that I am looking for solution that can allow us to add manually primary key into mapping and models class. I don't know we can do that or not. if you need more clearance then I can provide you – Bhavik Moradiya Feb 22 '16 at 14:45
-
You already said as much but that isn't enough. Check [the guidelines](http://stackoverflow.com/help/how-to-ask). Also check some [other questions with high ratings](http://stackoverflow.com/questions/3365134/how-to-make-a-method-generic-when-type-t-must-be-a-reference-type/3365152#3365152) on a topic similar to yours to give you a better idea on how to ask a good question. – Kris Feb 22 '16 at 14:49
-
ok simple, Is it possible for mapping between class and .hbm.xml without primary key for table ? – Bhavik Moradiya Feb 23 '16 at 13:54
-
Is there duplicate information in the table. i.e. multiple rows with the exact same values in all the columns? If the rows are unique. You could try mapping all the columns into a composite key. – Fran Feb 23 '16 at 15:16
-
there is some duplicate value into table but there is ROWID into Oralce table that is unique. – Bhavik Moradiya Feb 23 '16 at 18:21
1 Answers
NHibernate does not care about having an actual primary key in DB.
It will be enough to declare in your mappings what is 'logically' a primary key for each entity.
If you have some tables which do not have any combination of columns having unique values, handling those tables will be harder.
If you use some third party tool to generate the mapping and classes from DB, better forget it and write your own mappings and classes. Such tools may generate a decent mapping from a 'well shaped' DB, but are quite helpless on legacy DB not following common practices.
And even on 'good' DB, using some tools for generating mapping and model is generally not that good, because your domain model does not have to match precisely your DB. Tools will bluntly translate the DB schema to a domain model, while writing it allows to customize the model to the apps actual needs. (Defining filters for children collection or entities, defining inheritance models, not mapping unneeded columns or relations, having entities and entity's properties names different from their corresponding tables and columns, setting cache policies, batch-size attributes for batching lazy loads, ...)

- 9,364
- 3
- 62
- 112