Is there a way to set entity reference names from the database?
- Iām using database first.
- I have a table with multiple foreign keys to the same table (Address) as shown below.
- EF creates entity relations for the 2 addresses and sets the names to AddressReference and Address1Reference which is not as descriptive as I would like.
I know I can do this from the EF side with annotations but is there a way to set the entity reference names from the database?
CREATE TABLE [dbo].[Person] (
[ID] INT PRIMARY KEY IDENTITY NOT NULL,
[Name] NVARCHAR(50) NOT NULL,
[HomeAddressID] INT,
[WorkAddressID] INT
)
GO
CREATE INDEX [IX_Person_HomeAddressID] ON [dbo].[Person] ([HomeAddressID])
GO
CREATE INDEX [IX_Person_WorkAddressID] ON [dbo].[Person] ([WorkAddressID])
GO
ALTER TABLE [dbo].[Person] ADD CONSTRAINT [FK_Person_HomeAddressID] FOREIGN KEY ([HomeAddressID]) REFERENCES [Address] ([HomeAddressID])
GO
ALTER TABLE [dbo].[Person] ADD CONSTRAINT [FK_Person_WorkAddressID] FOREIGN KEY ([WorkAddressID]) REFERENCES [Address] ([WorkAddressID])
GO