Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 759283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:34:37+00:00 2026-05-14T15:34:37+00:00

When I right-click in a .EDMX file and click Generate Database From Model ,

  • 0

When I right-click in a .EDMX file and click Generate Database From Model, the resulting script is obviously wrong because of the table names. What it generates is the following script. Note the table names in the DROP TABLE part versus the CREATE TABLE part.

Why is this inconsistent?

This is obviously not a reusable script. What I created was an Entity named “Address” and an Entity named “Company”, etc (all singular). The EntitySet names are pluralized. The “Pluralize New Objects” boolean does not change this either. So what’s the deal?

For what it’s worth, I originally generated the EDMX by pointing it to a database that had tables with non-pluralized names and now that I’ve made some changes, I want to go back the other way. I’d like to have the option to go back and forth as neither the db-first nor the model-first model is ideal in all scenarios, and I have the control to ensure that there will be no merging issues from multiple people going both ways at the same time.

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- NOTE: if the constraint does not exist, an ignorable error will be reported.
-- --------------------------------------------------

    ALTER TABLE [Address] DROP CONSTRAINT [FK_Address_StateID-State_ID];
GO
    ALTER TABLE [Company] DROP CONSTRAINT [FK_Company_AddressID-Address_ID];
GO
    ALTER TABLE [Employee] DROP CONSTRAINT [FK_Employee_BossEmployeeID-Employee_ID];
GO
    ALTER TABLE [Employee] DROP CONSTRAINT [FK_Employee_CompanyID-Company_ID];
GO
    ALTER TABLE [Employee] DROP CONSTRAINT [FK_Employee_PersonID-Person_ID];
GO
    ALTER TABLE [Person] DROP CONSTRAINT [FK_Person_AddressID-Address_ID];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- NOTE: if the table does not exist, an ignorable error will be reported.
-- --------------------------------------------------

    DROP TABLE [Address];
GO
    DROP TABLE [Company];
GO
    DROP TABLE [Employee];
GO
    DROP TABLE [Person];
GO
    DROP TABLE [State];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Addresses'
CREATE TABLE [Addresses] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [StreetAddress] nvarchar(100)  NOT NULL,
    [City] nvarchar(100)  NOT NULL,
    [StateID] int  NOT NULL,
    [Zip] nvarchar(10)  NOT NULL
);
GO

-- Creating table 'Companies'
CREATE TABLE [Companies] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(100)  NOT NULL,
    [AddressID] int  NOT NULL
);
GO

-- Creating table 'People'
CREATE TABLE [People] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [FirstName] nvarchar(100)  NOT NULL,
    [LastName] nvarchar(100)  NOT NULL,
    [AddressID] int  NOT NULL
);
GO

-- Creating table 'States'
CREATE TABLE [States] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(100)  NOT NULL,
    [Abbreviation] nvarchar(2)  NOT NULL
);
GO

-- Creating table 'Employees'
CREATE TABLE [Employees] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [PersonID] int  NOT NULL,
    [CompanyID] int  NOT NULL,
    [Position] nvarchar(100)  NOT NULL,
    [BossEmployeeID] int  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Addresses'
ALTER TABLE [Addresses]
ADD CONSTRAINT [PK_Addresses]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'Companies'
ALTER TABLE [Companies]
ADD CONSTRAINT [PK_Companies]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'People'
ALTER TABLE [People]
ADD CONSTRAINT [PK_People]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'States'
ALTER TABLE [States]
ADD CONSTRAINT [PK_States]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'Employees'
ALTER TABLE [Employees]
ADD CONSTRAINT [PK_Employees]
    PRIMARY KEY ([ID] );
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [StateID] in table 'Addresses'
ALTER TABLE [Addresses]
ADD CONSTRAINT [FK_Address_StateID_State_ID]
    FOREIGN KEY ([StateID])
    REFERENCES [States]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Address_StateID_State_ID'
CREATE INDEX [IX_FK_Address_StateID_State_ID]
ON [Addresses]
    ([StateID]);
GO

-- Creating foreign key on [AddressID] in table 'Companies'
ALTER TABLE [Companies]
ADD CONSTRAINT [FK_Company_AddressID_Address_ID]
    FOREIGN KEY ([AddressID])
    REFERENCES [Addresses]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Company_AddressID_Address_ID'
CREATE INDEX [IX_FK_Company_AddressID_Address_ID]
ON [Companies]
    ([AddressID]);
GO

-- Creating foreign key on [AddressID] in table 'People'
ALTER TABLE [People]
ADD CONSTRAINT [FK_Person_AddressID_Address_ID]
    FOREIGN KEY ([AddressID])
    REFERENCES [Addresses]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Person_AddressID_Address_ID'
CREATE INDEX [IX_FK_Person_AddressID_Address_ID]
ON [People]
    ([AddressID]);
GO

-- Creating foreign key on [CompanyID] in table 'Employees'
ALTER TABLE [Employees]
ADD CONSTRAINT [FK_Employee_CompanyID_Company_ID]
    FOREIGN KEY ([CompanyID])
    REFERENCES [Companies]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Employee_CompanyID_Company_ID'
CREATE INDEX [IX_FK_Employee_CompanyID_Company_ID]
ON [Employees]
    ([CompanyID]);
GO

-- Creating foreign key on [BossEmployeeID] in table 'Employees'
ALTER TABLE [Employees]
ADD CONSTRAINT [FK_Employee_BossEmployeeID_Employee_ID]
    FOREIGN KEY ([BossEmployeeID])
    REFERENCES [Employees]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Employee_BossEmployeeID_Employee_ID'
CREATE INDEX [IX_FK_Employee_BossEmployeeID_Employee_ID]
ON [Employees]
    ([BossEmployeeID]);
GO

-- Creating foreign key on [PersonID] in table 'Employees'
ALTER TABLE [Employees]
ADD CONSTRAINT [FK_Employee_PersonID_Person_ID]
    FOREIGN KEY ([PersonID])
    REFERENCES [People]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Employee_PersonID_Person_ID'
CREATE INDEX [IX_FK_Employee_PersonID_Person_ID]
ON [Employees]
    ([PersonID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:34:38+00:00Added an answer on May 14, 2026 at 3:34 pm

    I have been unable to find an answer to this problem. In addition, I have had issues recreating this problem where I’m not going back and forth from DB-first to model-first scenarios. As such, I’m just assuming that back-and-forth has caused issues and is a bad situation to put EF through.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 376k
  • Answers 376k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Popup based on TitleWindow and Panel would be draggable by… May 14, 2026 at 8:32 pm
  • Editorial Team
    Editorial Team added an answer The ParameterizedThreadStart delegate only takes an Object parameter, so the… May 14, 2026 at 8:32 pm
  • Editorial Team
    Editorial Team added an answer While you're running your extraction process on the EDT, it… May 14, 2026 at 8:32 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.