NHibernate does not override foreign key constraints

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

schema.Create(true, true); 

I get:

 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. 

I grabbed the SQL code that used nHibernate, ran it directly from MSSMS, and got similar errors. Looking at it, the generated code does not correctly remove the foreign key constraints. The fall is as follows:

 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 

Execution "select OBJECT_ID (N'dbo [FK22212EAFBFE4C58]") "I get null. If I select" dbo "(ie" Choose OBJECT_ID (N '[FK22212EAFBFE4C58] "), then the identifier is returned.

So my question is: why does nHibernate add a dbo and why does this prevent the object from returning (since the table owning this restriction is dbo.XXX)

One of my mapping files:

 <?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> 
0
source share
1 answer

Answer:. This is probably a mistake. An entry has been entered for this exact one for SQL Server 2005 . Apparently, it is not flagged for SQL 2000, so I'm either reporting an error or fixing it.

0
source

All Articles