简体   繁体   English

使用Nhibernate(C#)的Oracle数据库映射(数据库不包含PK)

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

I do have giant Oracle Database which contain more than 1000 tables. 我确实有包含1000多个表的巨型Oracle数据库。 And some of them does not have PK(Primary Key). 并且其中一些没有PK(主键)。 I want to implement Nhibernate between C# and Oracle Database but it does not let me allow to do mapping because of primary Key. 我想在C#和Oracle数据库之间实现Nhibernate,但是由于主键,它不允许我进行映射。 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. NHibernate并不关心在数据库中有实际的主键。

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. 这样的工具可以从“形状良好”的数据库中生成一个不错的映射,但是对于没有遵循常规做法的旧式DB来说是完全无奈的。

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, ...) (为子集合或实体定义过滤器,定义继承模型,不映射不需要的列或关系,使实体和实体的属性名称与其对应的表和列不同,设置缓存策略,用于批量分配延迟加载的批量大小属性,... )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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