Nhibernate의 스키마 도구에서 생성 된 Sql Server db가 있는데 알려진 PartyId를 입력하려고 할 때 아래 오류가 발생하며 오류가 발생하지 않습니다. 내가는 FK 제약이 PartyId가 존재해야 말을 생각 디버깅 외래 키 제약 조건 오류
(I 보여주는거야 로그 출력이 자 NHibernate를 사용하여 테스트 실행에서하더라도 그래도, 내가 수동으로 NHib가 생성 된 SQL 서버 DB를 사용하여 오류를 복제 할 수 있습니다) 첫째로, 그러나 나가 말하는처럼 - 그것은.
SQL Server 2008 관리 스튜디오가 있지만 드문 시간에 Visual Studio를 통해 액세스하는 것을 선호합니다. 그래서 두 가지 기본적인 질문이 있습니다
- Visual Studio에서 SQL Server에 ddl을 어떻게 볼 수 있습니까?
- 내 FK 제약 조건을 디버그하고 수정하려면 어떻게해야합니까?
DDL은
NHibernate: INSERT INTO Parties (Type, PartyId) VALUES ('PERSON', @p0);@p0 = 98304 [Type: Int32 (0)]
NHibernate: INSERT INTO Parties (Type, PartyId) VALUES ('PERSON', @p0);@p0 = 98305 [Type: Int32 (0)]
NHibernate: INSERT INTO Parties (Type, PartyId) VALUES ('PERSON', @p0);@p0 = 98306 [Type: Int32 (0)]
NHibernate: select next_hi from hibernate_unique_key with (updlock, rowlock)
NHibernate: update hibernate_unique_key set next_hi = @p0 where next_hi = @p1;@p0 = 5 [Type: Int32 (0)], @p1 = 4 [Type: Int32 (0)]
NHibernate: INSERT INTO
PartyNames (PartyId, RequiredName, EverythingElse, ContextUsed, Salutation, EffectiveStart, EffectiveEnd, PartyNameId)
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7);
@p0 = 98304 [Type: Int32 (0)],
@p1 = 'Hesh' [Type: String (50)],
@p2 = 'Berryl;;;' [Type: String (4000)],
@p3 = 'Stack Overflow Profile' [Type: String (50)],
@p4 = 'Fellow Geek' [Type: String (20)],
@p5 = 7/29/2011 4:55:19 PM [Type: DateTime (0)],
@p6 = 12/31/9999 11:59:59 PM [Type: DateTime (0)],
@p7 = 131072 [Type: Int32 (0)]
Test 'Parties.Data.Impl.NHib.Tests.TestFixtures.BaseDataTestFixtures.SqlServerCommandExecutor.GenerateTestData' failed: NHibernate.Exceptions.GenericADOException : could not insert: [Parties.Domain.Names.PartyName#131072][SQL: INSERT INTO PartyNames (PartyId, RequiredName, EverythingElse, ContextUsed, Salutation, EffectiveStart, EffectiveEnd, PartyNameId) VALUES (?, ?, ?, ?, ?, ?, ?, ?)]
----> System.Data.SqlClient.SqlException :
The INSERT statement conflicted with the FOREIGN KEY constraint "Party_PartyName_FK".
The conflict occurred in database "PartyDomainDb", table "dbo.Parties", column 'PartyId'.
이 스크립트
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PartyNames](
[PartyNameId] [int] NOT NULL,
[PartyId] [int] NOT NULL,
[RequiredName] [nvarchar](50) NOT NULL,
[EverythingElse] [nvarchar](255) NULL,
[ContextUsed] [nvarchar](50) NULL,
[Salutation] [nvarchar](20) NULL,
[EffectiveStart] [datetime] NULL,
[EffectiveEnd] [datetime] NULL,
PRIMARY KEY CLUSTERED
(
[PartyNameId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[PartyNames] WITH CHECK ADD CONSTRAINT [Party_FK] FOREIGN KEY([PartyId])
REFERENCES [dbo].[Parties] ([PartyId])
GO
ALTER TABLE [dbo].[PartyNames] CHECK CONSTRAINT [Party_FK]
GO
ALTER TABLE [dbo].[PartyNames] WITH CHECK ADD CONSTRAINT [Party_PartyName_FK] FOREIGN KEY([PartyNameId])
REFERENCES [dbo].[Parties] ([PartyId])
GO
ALTER TABLE [dbo].[PartyNames] CHECK CONSTRAINT [Party_PartyName_FK]
GO
USE [PartyDomainDb]
GO
/****** Object: Table [dbo].[Parties] Script Date: 07/29/2011 18:22:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Parties](
[PartyId] [int] NOT NULL,
[Type] [nvarchar](255) NOT NULL,
PRIMARY KEY CLUSTERED
(
[PartyId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
FOREIGN KEY 제약 조건 정의는 어디에 있습니까? –
@ypercube. 질문의 일부입니다. Visual Studio 또는 SQL Server Mgt Studio에서 어떻게 찾을 수 있습니까? – Berryl
Mgt Studio (개체 탐색기)에서 테이블 -> 스크립트 테이블로 -> CREATE To -> Clipboard (또는 파일 또는 편집기 창) –