我正在研究.NET 4项目。最近,一个列被添加到表“T”中,之后其他表与表T的所有关联都丢失了(任何具有表T的外键的表现在都没有它)。我应该提一下,我们使用sqlmetal命令来更新与DBML相关的类文件。虽然DB经常更新并且以前没有出现过这样的问题,但这个问题突然发生了。
如果问题与SQL Server或LINQ有关,我没有任何线索。有人可以帮帮我吗?
表T:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[T](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Cid] [int] NULL,
[Guid] [uniqueidentifier] NOT NULL
CONSTRAINT [PK_T] PRIMARY KEY CLUSTERED
(
[Id] 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
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[T] WITH CHECK ADD CONSTRAINT [FK_T_C] FOREIGN KEY([Cid])
REFERENCES [dbo].[C] ([Id])
GO
ALTER TABLE [dbo].[T] CHECK CONSTRAINT [FK_T_C]
GO
ALTER TABLE [dbo].[T] ADD CONSTRAINT [DF_T_Guid] DEFAULT (newid()) FOR [Guid]
GO
表I具有表T中的外键:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[I](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](512) NOT NULL,
[TId] [int] NOT NULL,
[Desc] [nvarchar](2000) NULL,
[Guid] [uniqueidentifier] NOT NULL
CONSTRAINT [PK_I] PRIMARY KEY CLUSTERED
(
[Id] 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].[I] WITH CHECK ADD CONSTRAINT [FK_I_T] FOREIGN KEY([TId])
REFERENCES [dbo].[T] ([Id])
GO
ALTER TABLE [dbo].[I] CHECK CONSTRAINT [FK_I_T]
GO
ALTER TABLE [dbo].[I] ADD CONSTRAINT [DF_I_Guid] DEFAULT (newid()) FOR [Guid]
GO
答案 0 :(得分:0)
[不是一个答案,但在评论中写的时间太长了,也许会有所帮助]
由于数据库中存在约束,我认为问题不是SQL服务器。
也许你的项目内部存在问题。
检查DMBL - 是对还是错?
如果错了,我首先要做的是在Visual Studio中创建一个新的虚拟项目(Express?)并创建一个新的Linq-2-sql DBML文件,添加所有表并查看问题是否仍然存在。