是否有可能映射功能NHibernate组合键,其中一半的关键是在数据库中标识字段?是在、有可能、字段、数据库中

由网友(小情緒ぅ反反複複)分享简介:随着问题的国家,是有可能映射功能NHibernate组合键(或不流利我想),其中在复合材料中使用的两​​个领域之一是标识字段?As the question states, is it possible to map a composite key in fluent nhibernate (or non fluen...

随着问题的国家,是有可能映射功能NHibernate组合键(或不流利我想),其中在复合材料中使用的两​​个领域之一是标识字段?

As the question states, is it possible to map a composite key in fluent nhibernate (or non fluent i suppose) where one of the two fields used in the composite is an identity field?

我有一个表,其中的主密钥中的一个部分是一个标识字段,另一个是一个租户的id。这是在复合键遍用作外键遗留数据库,所以修改数据库将是相当显著

I have a table where one part of the primary key is an identity field and the other is a tenant id. This is a legacy database where the composite key is used as foreign keys all over, so modifying the database would be quite significant.

谢谢!

推荐答案

如果它是一个真正的标识列,那么它的保证是唯一的每个记录,对吧?

If it's really an identity column, then it's guaranteed to be unique for every record, right?

如果是这样,你可以完全忽略的租赁ID映射的目的。你的标识字段将在您的主表独特的 - 和你的外键引用将包含这个唯一的ID,所以租赁ID实际上是无关紧要的。

If so, you can ignore the tenancy ID completely for mapping purposes. Your identity fields will be unique in your primary table - AND your foreign key references will contain this unique Id, so the tenancy ID is actually irrelevant.

NHibernate的并不真正关心无论你是完全映射数据库架构。我已经与传统数据库的工作之前,我已经定义在一个非键列的唯一约束,然后告诉NHibernate的使用,作为主键 - 它的工作原理,并能巧妙地避开各种可怕的复合键关系映射。

NHibernate doesn't really care whether you're mapping your database schema exactly. I've worked with legacy databases before where I've defined a unique constraint on a non-key column and then told NHibernate to use that as the primary key - it works, and it can neatly sidestep all kinds of horrific composite-key relationship mappings.

想想吧。反直觉的,但它可能会工作

Think about it. Counter-intuitive, but it will probably work.

阅读全文

相关推荐

最新文章