当前位置: 首页 > 面试题库 >

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

姜阳
2023-03-14
问题内容

在这些多重性冲突中,我所看到的大多数其他问题都是代码优先的,而我将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

问题答案:

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

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



 类似资料:
  • 我有一个带有“Status”布尔值的付款模型,该布尔值默认为false。付款后,我需要将特定付款的“状态”更新为true。 这是我一直试图用来更改特定数据库条目的代码,但它并没有改变它。我做错了什么? 谢谢 这就是最终起作用的原因:

  • 问题内容: 我想建立这样的关系(一个区域在x个其他区域的附近) 不幸的是,这是行不通的,因为EF生成的FK不正确…我如何才能使像这样的结构起作用? 3个区域的示例:3 Zones: Zone 1, Zone 2, Zone 3 Zone 1 Neighours: Zone 2, Zone 3 Zone 2 Neighbours: Zone 1 Zone 3 Neighbours: Zone1 有什

  • 好吧,我知道我对C#和MVC还很陌生,但我正在尝试使用代码优先的方法向数据库中添加项。 现在,我已经成功地为数据库创建了新条目,但当我转到SQL Server时,却找不到数据库或表。 因此,我的问题是,这些数据存储在哪里,因为我无法在SQL Server中看到它,就像我手动创建的其他数据库一样? 我的ConnectionString是:

  • 因此,我使用实体框架的“代码优先”方法,并且我有映射文件来映射表信息并添加诸如验证之类的内容,例如: 这是在使用Fluent API,我想知道如何通过字符串而不是T.AccountName获得属性名。我想动态设置这些属性,但我不知道如何通过编程实现。

  • 我曾想过简单地对数据库运行一个小命令并捕获任何异常,然而,如果出现问题(例如app.config丢失或数据库服务器关闭),应用程序将花费大量时间运行此代码,然后抛出异常(大约1分钟)。我想这是由于连接超时等,但我已经摆弄了这样的属性没有任何作用。 有没有人能提供任何关于去哪里的建议?

  • 场景: 我有两个MySQL数据库: 大型主数据库 小型客户端数据库 示例表: 大数据库用户: 文本用户名 int id varchar登录 varchar密码 ...更多的领域 客户端数据库用户 内部id int UNIQUE api\u id(来自master的id) varchar登录 varchar密码 问题:我需要同步数据库,但我不知道如何以最佳方式进行同步。我读过这个问题,但它很老了,没