小编典典

实体框架数据库更新优先多重性冲突

sql

在这些多重性冲突中,我所看到的大多数其他问题都是代码优先的,而我将DB作为第一位。我进行了一些模式更改,并且从数据库刷新模型时出现以下错误:

多重性与关系“
FK_MarketSelectionWager_Bet”中的角色“赌注”中的引用约束冲突。由于从属角色中的所有属性都是不可为空的,因此,主体角色的多重性必须为“
1”。

我需要在SQL或模型中进行修复的任何指针都很棒。

以下是涉及的SQL表:

MarketSelectionWager* /
__对象:表格[dbo]。[MarketSelectionWager]脚本日期:2014年1月31日12:08:34 ***
/进行设置ANSI_NULLS

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

阅读 249

收藏
2021-03-08

共1个答案

小编典典

当实体框架从数据库更新模型时,它会执行某些操作,而不会执行某些操作。它添加了新的对象,字段和关联等等(我认为只有EF团队才能提供详尽的列表)。我已经体验到它
不会 更新概念模型中的多重性约束。

因此,当您NOT NULL向数据库中的列添加约束时(BetId根据您的情况), 商店模型 将被更新,但是 概念模型
(类模型)将挂在初始的可为空的关联(0..1 - n)上。您会注意到,该模型不再通过其验证,并且看起来非常可怕(毕竟,您仅进行了更新),但是修复很简单:在edmx设计器中,手动更改这样的关联1-n

2021-03-08