我在这些多重冲突中看到的大多数其他问题都是代码优先,在那里 - 因为我首先要DB。我做了一些架构更改,当我从数据库刷新模型时出现以下错误:
多重性与关系'FK_MarketSelectionWager_Bet'中角色'Bet'中的引用约束冲突。由于“从属角色”中的所有属性都是不可为空的,因此“主体角色”的多重性必须为“1”。
关于我需要做什么来修复SQL或我的模型的任何指针都会很棒。
以下是涉及的SQL表:
MarketSelectionWager / * 对象:表[dbo]。[MarketSelectionWager]脚本日期:31/01/2014 12:08:34 < / EM> * / SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[MarketSelectionWager](
[MarketSelectionWagerIdentifier] [varchar](255) NOT NULL,
[MarketIdentifier] [varchar](255) NULL,
[SelectionName] [varchar](255) NULL,
[SelectionIdentifier] [varchar](255) NULL,
[WagerIdentifier] [varchar](255) NULL,
[PriceType] [varchar](5) NULL,
[PriceFrac] [varchar](50) NULL,
[WagerStakeWin] [money] NULL,
[WagerStakePlace] [money] NULL,
[RunningStakeWin] [money] NULL,
[RunningStakePlace] [money] NULL,
[LiabilityWin] [money] NULL,
[LiabilityPlace] [money] NULL,
[BetIdentifier] [varchar](255) NULL,
[BetCombinationIndex] [int] NULL,
[WagerStatus] [int] NULL,
[NumberRunningAfter] [int] NULL,
[NumberRunningSameTime] [int] NULL,
[TimeToNextRemainingRunner] [int] NULL,
[HasOtherSelectionsRunningSameTime] [bit] NULL,
[HasOtherSelectionsRunningAfter] [bit] NULL,
[BetId] [int] NOT NULL,
CONSTRAINT [PK_MarketLiabilty] PRIMARY KEY CLUSTERED
(
[MarketSelectionWagerIdentifier] ASC,
[BetId] 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].[MarketSelectionWager] WITH CHECK ADD CONSTRAINT [FK_MarketSelectionWager_Bet] FOREIGN KEY([BetId])
REFERENCES [dbo].[Bet] ([BetID])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[MarketSelectionWager] CHECK CONSTRAINT [FK_MarketSelectionWager_Bet]
GO
赌注
/****** Object: Table [dbo].[Bet] Script Date: 31/01/2014 12:09:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Bet](
[BetID] [int] IDENTITY(1,1) NOT NULL,
[BetSlipID] [int] NOT NULL,
[BetPayout] [money] NULL,
[BetPotentialReturn] [money] NULL,
[BetStake] [money] NULL,
[BetRefund] [money] NULL,
[DateBetSettled] [datetime] NULL,
[SettleStatusID] [int] NULL,
[SportID] [int] NULL,
[tsTimestamp] [timestamp] NULL,
[SportMixID] [int] NULL,
[WagerTypeMixID] [int] NULL,
[EventMixID] [int] NULL,
[MarketMixID] [int] NULL,
[SettleTypeID] [int] NULL,
[MaxOffDate] [datetime] NULL,
CONSTRAINT [PK_Bet] PRIMARY KEY CLUSTERED
(
[BetID] 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].[Bet] ADD CONSTRAINT [DF_BS_Bet_BetPayout] DEFAULT ((0)) FOR [BetPayout]
GO
ALTER TABLE [dbo].[Bet] ADD CONSTRAINT [DF_BS_Bet_BetPotentialReturn] DEFAULT ((0)) FOR [BetPotentialReturn]
GO
ALTER TABLE [dbo].[Bet] ADD CONSTRAINT [DF_BS_Bet_BetStake] DEFAULT ((0)) FOR [BetStake]
GO
ALTER TABLE [dbo].[Bet] ADD CONSTRAINT [DF_BS_Bet_BetRefund] DEFAULT ((0)) FOR [BetRefund]
GO
ALTER TABLE [dbo].[Bet] WITH CHECK ADD CONSTRAINT [FK_Bet_BetSlip] FOREIGN KEY([BetSlipID])
REFERENCES [dbo].[BetSlip] ([BetSlipId])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Bet] CHECK CONSTRAINT [FK_Bet_BetSlip]
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnHidden', @value=0 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnOrder', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnWidth', @value=-1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnHidden', @value=0 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetSlipID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnOrder', @value=0 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetSlipID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnWidth', @value=-1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetSlipID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnHidden', @value=0 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetPayout'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnOrder', @value=0 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetPayout'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnWidth', @value=-1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetPayout'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnHidden', @value=0 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetPotentialReturn'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnOrder', @value=0 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetPotentialReturn'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnWidth', @value=2250 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetPotentialReturn'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnHidden', @value=0 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetStake'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnOrder', @value=0 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetStake'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnWidth', @value=-1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetStake'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnHidden', @value=0 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetRefund'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnOrder', @value=0 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetRefund'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnWidth', @value=-1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'BetRefund'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnHidden', @value=0 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'DateBetSettled'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnOrder', @value=0 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'DateBetSettled'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_ColumnWidth', @value=-1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet', @level2type=N'COLUMN',@level2name=N'DateBetSettled'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DefaultView', @value=0x02 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Filter', @value=NULL , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_LinkChildFields', @value=N'BetID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_LinkMasterFields', @value=N'BetID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_OrderBy', @value=NULL , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_OrderByOn', @value=0 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Orientation', @value=0x00 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_SubdatasheetName', @value=N'dbo.BS_Selection' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_TableMaxRecords', @value=10000 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Bet'
GO
答案 0 :(得分:5)
当Entity框架从数据库更新模型时,它会执行和不执行任务。它添加了新的对象,字段和关联等等(我认为只有EF团队才能生成详尽的列表)。我经历过不更新概念模型中的多重约束。
因此,当您向数据库中的列添加NOT NULL
约束时(在您的情况下为BetId
),商店模型将会更新,但概念模型(类模型)将挂起到初始可为空的关联(0..1 - n
)。您会注意到该模型不再通过其验证并且看起来非常可怕(毕竟,您只更新了),但修复很简单:在edmx设计器中,手动更改“1”侧的多重性该关联因此变为1-n
。