简体   繁体   中英

Oracle Database mapping with Nhibernate (C#)(database does not contain PK)

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.

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, ...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM