0

I'm updating my Model from database and get two problems:

  1. MachineInfo1 and MachineInfo2 properties inside MachineInfo model definition should not exist
  2. The 0..1 association instead of 1 to many table association between MachineInfo and DisplayAdapter tables

I already know that not having a key defined inside the DisplayAdapter table can be an issue as explained here and here but even with this info, I don't know how to resolve the issue.

How can I fix this?

enter image description here

The full db schema stucture follows:

USE [sales]
GO
/****** Object:  Table [dbo].[Activation]    Script Date: 12/30/2019 4:31:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Activation](
    [SerialNumber] [nvarchar](256) NOT NULL,
    [ReferenceId] [int] NOT NULL,
    [ProfileHash] [nvarchar](256) NOT NULL,
    [DateActivated] [datetime] NOT NULL,
    [MachineNickname] [nvarchar](256) NULL,
    [AllowNewMachine] [bit] NOT NULL,
    [LastSeen] [datetime] NOT NULL,
 CONSTRAINT [PK_XHEO_Activation_Activation] PRIMARY KEY CLUSTERED 
(
    [SerialNumber] ASC,
    [ReferenceId] 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
/****** Object:  Table [dbo].[ActivationLog]    Script Date: 12/30/2019 4:31:20 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ActivationLog](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [SerialNumber] [nvarchar](256) NOT NULL,
    [ReferenceId] [int] NOT NULL,
    [ProfileHash] [nvarchar](256) NOT NULL,
    [DateAndTime] [datetime] NOT NULL,
    [Operation] [tinyint] NOT NULL,
    [UserName] [nvarchar](256) NULL,
    [IpAddress] [nvarchar](50) NOT NULL,
    [LicensedAssemblyVersion] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_ActivationLog] 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
/****** Object:  Table [dbo].[DisplayAdapters]    Script Date: 12/30/2019 4:31:21 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DisplayAdapters](
    [ProfileHash] [nvarchar](256) NOT NULL,
    [Manufacturer] [nvarchar](256) NULL,
    [ChipType] [nvarchar](256) NULL,
    [Memory] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MachineInfo]    Script Date: 12/30/2019 4:31:21 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MachineInfo](
    [ProfileHash] [nvarchar](256) NOT NULL,
    [Name] [nvarchar](256) NULL,
    [IsVirtual] [bit] NULL,
    [OperatingSystem] [nvarchar](256) NULL,
    [Manufacturer] [nvarchar](256) NULL,
    [Model] [nvarchar](256) NULL,
    [Processor] [nvarchar](256) NULL,
    [PhysicalMemory] [int] NULL,
 CONSTRAINT [PK_MachineInfo] PRIMARY KEY CLUSTERED 
(
    [ProfileHash] 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].[Activation]  WITH CHECK ADD  CONSTRAINT [FK_Activation_License] FOREIGN KEY([SerialNumber])
REFERENCES [dbo].[License] ([SerialNumber])
GO
ALTER TABLE [dbo].[Activation] CHECK CONSTRAINT [FK_Activation_License]
GO
ALTER TABLE [dbo].[ActivationLog]  WITH CHECK ADD  CONSTRAINT [FK_ActivationLog_MachineInfo] FOREIGN KEY([ProfileHash])
REFERENCES [dbo].[MachineInfo] ([ProfileHash])
GO
ALTER TABLE [dbo].[ActivationLog] CHECK CONSTRAINT [FK_ActivationLog_MachineInfo]
GO
ALTER TABLE [dbo].[DisplayAdapters]  WITH CHECK ADD  CONSTRAINT [FK_DisplayAdapters_MachineInfo] FOREIGN KEY([ProfileHash])
REFERENCES [dbo].[MachineInfo] ([ProfileHash])
GO
ALTER TABLE [dbo].[DisplayAdapters] CHECK CONSTRAINT [FK_DisplayAdapters_MachineInfo]
GO
abenci
  • 8,422
  • 19
  • 69
  • 134
  • MachineInfo table is still missing 2 navigation columns! – Parimal Raj Dec 30 '19 at 18:37
  • @PaRiMaLRaJ: what do you mean exactly? – abenci Dec 30 '19 at 19:57
  • The EF designer, when updating the model, selected DisplayAdapter.ProfileHash as PK. Relations between two primary keys is always 1 to 1 or 1 to 0..1. Also, when you remove a column from DB and then update the model, the designer usually doesn't remove old properties. You can try removing all four entities and then update the model adding the tables again, but first, if you want 1 to many relation between MachineInfo and DisplayAdapter, fix database schema, creating primary key in DisplayAdapter and foreign key between two tables (allready done with the relation between ProfileHash fields). – Pepelui360 Dec 31 '19 at 16:00
  • @Pepelui: Thanks. Will try your recommendations and let you know. – abenci Jan 02 '20 at 11:06

0 Answers0