sjh37 / EntityFramework-Reverse-POCO-Code-First-Generator

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from
https://www.reversepoco.co.uk/
Other
706 stars 230 forks source link

One to one relationship has incorrect table.NameHumanCase on Configuration/Mapping generation #716

Closed FaizulHussain closed 2 years ago

FaizulHussain commented 3 years ago

Hi,

I think there might be an issue with One2One relationship reverse mapping.

If I have these tables:

CREATE TABLE [dbo].[A]
(
    [Id] UNIQUEIDENTIFIER PRIMARY KEY,
    [Name] NVARCHAR(256)
)
GO
CREATE TABLE [dbo].[B]
(
    [Id] UNIQUEIDENTIFIER PRIMARY KEY FOREIGN KEY REFERENCES [dbo].[A] ([Id]),
    [Description] NVARCHAR(MAX)
)
GO

With rename table handler adding suffix like "Entity", then it generates the mapping as:

// Foreign keys
builder
   .HasOne(a => a.B)
   .WithOne(b => b.A)
   .HasForeignKey<**B**>(c => c.Id)
   .OnDelete(DeleteBehavior.ClientSetNull)
   .HasConstraintName("FK_dbo_B_Id_A");

The class names are correctly generated with the renamed suffix (AEntity, BEntity etc...)

case Relationship.OneToOne:
return string.Format(".WithOne({0}){1}.HasForeignKey<{2}>({3})",
   withParam, hasPrincipleKey, **fkTableNameHumanCase**, manyToManyMapping);

Thanks

FaizulHussain commented 3 years ago

I changed the line 4851

var rel = GetRelationship(relationship, fkCols2, pkCols2, pkPropName, fkPropName, manyToManyMapping, mapKey, foreignKey.CascadeOnDelete, foreignKey.IncludeReverseNavigation, foreignKey.IsNotEnforced, foreignKey.ConstraintName, pkTableHumanCase, fkTable.NameHumanCase**WithSuffix()**, primaryKeyColumns, fkHasUniqueConstraint);

that did the trick

Thanks

sjh37 commented 2 years ago

Thanks @FaizulHussain This will be in the next release :-)

sjh37 commented 2 years ago

Now released in v3.5.0