-
Notifications
You must be signed in to change notification settings - Fork 53
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
With setting of handlebar transformer:
public void ConfigureDesignTimeServices(IServiceCollection serviceCollection)
{
serviceCollection.AddHandlebarsScaffolding();
serviceCollection.AddHandlebarsTransformers(
entityFileNameTransformer: x => x + "DAO",
entityTypeNameTransformer: x => x + "DAO",
constructorTransformer: x =>
{
x.PropertyType += "DAO";
return x;
},
navPropertyTransformer: x =>
{
x.PropertyType += "DAO";
return x;
});
serviceCollection.AddSingleton<IPluralizer, Pluralizer>();
}
DbContext will be generated by reverse engine and used CodeTemplates in Handlebars.
Class of Action and Permission after generated like this:
public partial class ActionDAO
{
public ActionDAO()
{
Pages = new HashSet<PageDAO>();
Permissions = new HashSet<PermissionDAO>();
}
public long Id { get; set; }
public string Name { get; set; } = null!;
public long MenuId { get; set; }
public bool IsDeleted { get; set; }
public virtual MenuDAO Menu { get; set; } = null!;
public virtual ICollection<PageDAO> Pages { get; set; }
public virtual ICollection<PermissionDAO> Permissions { get; set; }
}
public partial class PageDAO
{
public PageDAO()
{
Actions = new HashSet<ActionDAO>();
}
public long Id { get; set; }
public string Name { get; set; } = null!;
public string Path { get; set; } = null!;
public long MenuId { get; set; }
public bool IsDeleted { get; set; }
public virtual ICollection<ActionDAO> Actions { get; set; }
}
The errors appear in OnModelCreating(ModelBuilder modelBuilder), in sections of mapping table
entity.HasMany(d => d.PagesDAO)
.WithMany(p => p.ActionsDAO)
.UsingEntity<Dictionary<string, object>>(
"ActionPageMapping",
l => l.HasOne<PageDAO>().WithMany().HasForeignKey("PageId").OnDelete(DeleteBehavior.ClientSetNull).HasConstraintName("FK_ActionPageMapping_Page"),
r => r.HasOne<ActionDAO>().WithMany().HasForeignKey("ActionId").OnDelete(DeleteBehavior.ClientSetNull).HasConstraintName("FK_ActionPageMapping_Action"),
j =>
{
j.HasKey("ActionId", "PageId");
j.ToTable("ActionPageMapping", "PER");
});
"entity.HasMany(d => d.PagesDAO)" should be "entity.HasMany(d => d.Pages)"
and ".WithMany(p => p.ActionsDAO)" should be ".WithMany(p => p.Actions)"
Expected behavior
Template should generate
entity.HasMany(d => d.Pages)
.WithMany(p => p.Actions)
.UsingEntity<Dictionary<string, object>>(
"ActionPageMapping",
l => l.HasOne<PageDAO>().WithMany().HasForeignKey("PageId").OnDelete(DeleteBehavior.ClientSetNull).HasConstraintName("FK_ActionPageMapping_Page"),
r => r.HasOne<ActionDAO>().WithMany().HasForeignKey("ActionId").OnDelete(DeleteBehavior.ClientSetNull).HasConstraintName("FK_ActionPageMapping_Action"),
j =>
{
j.HasKey("ActionId", "PageId");
j.ToTable("ActionPageMapping", "PER");
});
tjaadvd and Freddie-H
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working