my task is very simple, i need to create a library mvc web app that allows crud operations, the only constraints are that 1 book can have multiple authors and can also have multiple publishers.
to accomplish this, this is my database model:
and the respective sql code for the books->books_authors->authors table relationships, the publishers relationship is defined in the same way
CREATE TABLE [dbo].[BOOKS](
[ID] [int] NOT NULL,
[TITLE] [nvarchar](max) NOT NULL,
[PAGES] [int] NOT NULL,
[SYNOPSIS] [nvarchar](max) NOT NULL,
[PUBLISHDATE] [date] NOT NULL,
[ISBN] [nvarchar](max) NOT NULL,
[SUBJECT] [nvarchar](max) NOT NULL,
CONSTRAINT [PK_BOOKS] 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] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[BOOKS_AUTHORS](
[BOOKID] [int] NOT NULL,
[AUTHORID] [int] NOT NULL,
CONSTRAINT [PK_BOOKS_AUTHORS] PRIMARY KEY CLUSTERED
(
[BOOKID] ASC,
[AUTHORID] 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].[BOOKS_AUTHORS] WITH CHECK ADD CONSTRAINT [FK_BOOKS_AUTHORS_AUTHORS] FOREIGN KEY([AUTHORID])
REFERENCES [dbo].[AUTHORS] ([ID])
GO
ALTER TABLE [dbo].[BOOKS_AUTHORS] CHECK CONSTRAINT [FK_BOOKS_AUTHORS_AUTHORS]
GO
ALTER TABLE [dbo].[BOOKS_AUTHORS] WITH CHECK ADD CONSTRAINT [FK_BOOKS_AUTHORS_BOOKS1] FOREIGN KEY([BOOKID])
REFERENCES [dbo].[BOOKS] ([ID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[BOOKS_AUTHORS] CHECK CONSTRAINT [FK_BOOKS_AUTHORS_BOOKS1]
GO
CREATE TABLE [dbo].[AUTHORS](
[ID] [int] NOT NULL,
[FIRSTNAME] [nvarchar](max) NOT NULL,
[LASTNAME] [nvarchar](max) NOT NULL,
CONSTRAINT [PK_AUTHORS] 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] TEXTIMAGE_ON [PRIMARY]
GO
now onto my issues, when i add a ado.net model to the mvc web app, the edmx looks like this:
i thought i defined a 1 to many relationship between BOOKS and BOOKS_AUTHORS/BOOKS_PUBLISHERS, why is it now showing up on the edmx?
my other issue is that given the above edmx model, when i create a scaffolded controller with views, the create action lists the ID field from BOOKS as an input instead of hiding it while on the index action the same ID field is hidden, like so: