Reputation: 67241
I've created a Companies table with foreign key (ParentCompaniesId
) to the primary key of the same table.
When I generate an Entity Framework model from the database, it adds a ParentCompany
property, just as I want. However, it also adds a collection property called Companies1
to represent the many side of this same relationship.
Why Companies1
? Is there any way to have it name this property Companies
instead?
My table is similar to the one scripted below.
CREATE TABLE [dbo].[Companies](
[CompaniesId] [int] IDENTITY(1,1) NOT NULL,
[ParentCompaniesId] [int] NULL,
[Description] [nvarchar](100) NOT NULL,
CONSTRAINT [PK_Companies] PRIMARY KEY CLUSTERED
(
[CompaniesId] 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].[Companies] WITH CHECK ADD CONSTRAINT [FK_Companies_Companies] FOREIGN KEY([ParentCompaniesId])
REFERENCES [dbo].[Companies] ([CompaniesId])
GO
ALTER TABLE [dbo].[Companies] CHECK CONSTRAINT [FK_Companies_Companies]
GO
Upvotes: 0
Views: 64
Reputation: 364349
This is bug in the designer - actually the only thing in conceptual model I'm aware of which doesn't survive update from database. There is not much to do with this. You can use simple script / app. which will be run manually after Update from database to replace all these unexpected names with expected one. You can also give up with Update from database and maintain EDMX manually (it is XML file).
Upvotes: 1