msawczyn / EFDesigner

Entity Framework visual design surface and code-first code generation for EF6, Core and beyond
MIT License
363 stars 60 forks source link

Add association classes for EFCore5+ #229

Closed msawczyn closed 2 years ago

msawczyn commented 3 years ago

From https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-5.0/whatsnew

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder
        .Entity<Post>()
        .HasMany(p => p.Tags)
        .WithMany(p => p.Posts)
        .UsingEntity<PostTag>(
            j => j
                .HasOne(pt => pt.Tag)
                .WithMany()
                .HasForeignKey(pt => pt.TagId),
            j => j
                .HasOne(pt => pt.Post)
                .WithMany()
                .HasForeignKey(pt => pt.PostId),
            j =>
            {
                j.Property(pt => pt.PublicationDate).HasDefaultValueSql("CURRENT_TIMESTAMP");
                j.HasKey(t => new { t.PostId, t.TagId });
            });
}
msawczyn commented 3 years ago

Visual representation should be a UML association class, similar to image Note that this kind of visual isn't currently supported by the Modeling SDK, so we'll have to come up with something clever.

msawczyn commented 2 years ago

Implemented in VS2022