EFDesigner icon indicating copy to clipboard operation
EFDesigner copied to clipboard

Add association classes for EFCore5+

Open msawczyn opened this issue 5 years ago • 1 comments

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 avatar Nov 02 '20 12:11 msawczyn

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 avatar Jan 29 '21 12:01 msawczyn

Implemented in VS2022

msawczyn avatar Aug 14 '22 19:08 msawczyn