NHibernate不放弃外键约束 [英] NHibernate not dropping foreign key constraints

查看:79
本文介绍了NHibernate不放弃外键约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是NHibernate的新手,所以这可能是我的错误,但是当我使用时:

I'm new to NHibernate, so this is probably my mistake, but when I use:

schema.Create(true, true);

我得到:

SchemaExport [(null)]- There is already an object named 'XXX' in the database.
System.Data.SqlClient.SqlException: There is already an object 
named 'XXX' in the database.

我抓取了nHibernate使用的SQL代码,直接从MSSMS运行它,并收到了类似的错误.仔细研究一下,生成的代码没有正确删除外键约束.下落看起来像这样:

I grabbed the SQL code nHibernate was using, ran it directly from MSSMS, and recieved similar errors. Looking into it, the generated code is not properly dropping the foreign key constraints. The drop looks like this:

if exists (select 1 from sysobjects where id = OBJECT_ID(N'dbo[FK22212EAFBFE4C58]')
AND parent_obj = OBJECT_ID('YYY'))
alter table dbo.YYY  drop constraint FK22212EAFBFE4C58

执行"select OBJECT_ID(N'dbo [FK22212EAFBFE4C58]')"时,我得到了空值.如果我取出"dbo"(即选择OBJECT_ID(N'[FK22212EAFBFE4C58]')"),则返回ID.

Doing a "select OBJECT_ID(N'dbo[FK22212EAFBFE4C58]')" I get null. If I take out the "dbo" (i.e. "select OBJECT_ID(N'[FK22212EAFBFE4C58]')") then the ID is returned.

所以,我的问题是,为什么nHibernate添加dbo,以及为什么这样做会阻止对象被返回(因为拥有约束的表是dbo.XXX)

So, my question is, why is nHibernate adding the dbo, and why does that prevent the object from being returned (since the table owning the constraint is dbo.XXX)

我的一个映射文件:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping namespace="CanineApp.Model" assembly="CanineApp.Model" xmlns="urn:nhibernate-mapping-2.2">
  <class name="MedicalLog" table="MedicalLog" schema="dbo">
    <id name="MedicalLogID" type="Int64">
      <generator class="identity" />
    </id>
    <property name="InvoiceAmount" type="Decimal" not-null="true" />
    ...
    <many-to-one name="Canine" class="Canine" column="CanineID" not-null="true" fetch="join" />
    <many-to-one name="TreatmentCategory" class="TreatmentCategory" column="TreatmentCategoryID" not-null="true" access="field.camelcase-underscore" />
  </class>
</hibernate-mapping>

推荐答案

答案:. 这可能是一个错误.对于此确切的 SQL Server 2005问题,有一个条目.它似乎没有被标记为SQL 2000,所以我将创建一个错误报告或对其进行修复.

Answer: . It's probably a bug. There was an entry for this exact issue for SQL Server 2005. It doesn't appear to have been flagged for SQL 2000, so I'll either create a bug report or fix it.

这篇关于NHibernate不放弃外键约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆