EntityFramework-Reverse-POCO-Code-First-Generator
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard
Incorrect pluralization of reverse navigation property name?
I have a many-to-many relationship between my two tables in my issue tracking database:
My Issue table is related to my UploadedFile table via a many-to-many association in the IssueUploadedFile table.
This generates a nice set of POCOs, with the following navigation properties:
-
Issue.cscontains anICollection<UploadedFile>property calledUploadedFiles- plural - as expected -
UploadedFile.cscontains anICollection<Issue>property calledIssues- plural - as expected
I now add a new column to my Issue table and define it as a foreign key to the UploadedFile table, to reference a specific UploadedFile for the issue - in this case, the consent document for the issue.
This results in the pluralization of the previously-generated reverse navigation property to change from Issues to Issue - i.e. it has gone singular.
Am I doing something wrong here? Is it possible to modify my template in order to obtain the correct pluralization of the reverse navigation property?
Hi.
I don't know why that has happened. Could you send me the relevant schema for those tables, and I will try and re-create your problem.
You can control the singular and plural forms by adding a custom entry.
see the comments in Inflector.PluralizationService = new EnglishPluralizationService(new[] ...
Let me know if adding
Inflector.PluralizationService = new EnglishPluralizationService(new[]
{
new CustomPluralizationEntry("Issue", "Issues")
});
solves your issue.
Any update?
Apologies for the delay in getting back to you on this.
If I run the generator against the following tables, I get the POCOs generated with the expected pluralization as described in my original post:
create table UploadedFile
(
Id int identity(1, 1) not null,
FullPath nvarchar(max) not null,
constraint PK_UploadedFile primary key clustered(Id)
)
create table Issue
(
Id int identity(1, 1) not null,
Title nvarchar(100) not null,
Content nvarchar(max) null,
constraint PK_Issue primary key clustered(Id)
)
create table IssueUploadedFile
(
UploadedFileId int not null,
IssueId int not null,
constraint PK_IssueUploadedFile primary key clustered(UploadedFileId, IssueId),
constraint FK_IssueUploadedFile_UploadedFile foreign key (UploadedFileId) references UploadedFile(Id),
constraint FK_IssueUploadedFile_Issue foreign key (IssueId) references Issue(Id),
)
I then add the ConsentDocumentId column to my Issue table, along with its foreign key:
alter table Issue add ConsentDocumentId int null
alter table Issue add constraint FK_Issue_UploadedFileConsentDocument foreign key(ConsentDocumentId) references UploadedFile(Id)
This results in the Issue POCO receiving an int? ConsentDocumentId property and an UploadedFile (singular) foreign key property, as expected, and the navigation property UploadedFiles remains with the correct pluralization.
However, the UploadedFile POCO now has two properties of type ICollection<Issue> - one named ConsentDocument and the other named Issue - both singular.
I guess I'm asking - is there's a way of overriding the names that the generator gives to the two ICollection<Issue> properties in the UploadedFile POCO?
Thanks. I have replicated the issue :-)