Closed neonleo closed 2 years ago
PlaylistTrack entity needs a parameterless constructor.
From: Leo Cheung @.> Sent: Saturday, July 23, 2022 7:16:13 PM To: edandersen/core-admin @.> Cc: Subscribed @.***> Subject: [edandersen/core-admin] MissingMethodException if the Entity only contains foreign key column (Issue #74)
I using the chinook sample DBhttps://github.com/lerocha/chinook-database/tree/master/ChinookDatabase/DataSources to trying core admin, the (PlaylistTrack) table reference to (PlayList) and (Track) tables, and I have check both of this table is work fine on core admin, And the DB schema: CREATE TABLE [PlaylistTrack] ( [PlaylistId] INTEGER NOT NULL, [TrackId] INTEGER NOT NULL, CONSTRAINT [PK_PlaylistTrack] PRIMARY KEY ([PlaylistId], [TrackId]), FOREIGN KEY ([PlaylistId]) REFERENCES [Playlist] ([PlaylistId]) ON DELETE NO ACTION ON UPDATE NO ACTION, FOREIGN KEY ([TrackId]) REFERENCES [Track] ([TrackId]) ON DELETE NO ACTION ON UPDATE NO ACTION )
The EntityClass: `using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema;
namespace ApplicationCore.Entities { [Table("PlaylistTrack")] public class PlayListTrack { private long _PlayListId; [Display(AutoGenerateField = false)] // prevent showing on the grid public long PlayListId { get { return _PlayListId; } set { _PlayListId = value; } }
private long _TrackId;
[Display(AutoGenerateField = false)] // prevent showing on the grid
public long TrackId
{
get { return _TrackId; }
set { _TrackId = value; }
}
[ForeignKey("PlayListId")]
public virtual PlayList? PlayList { get; set; }
[ForeignKey("TrackId")]
public virtual Track? Track { get; set; }
public PlayListTrack(long playListId, long trackId)
{
this.PlayListId = playListId;
this.TrackId = trackId;
}
}
} ` The RepositoryContext class as well:
`using Microsoft.EntityFrameworkCore;
namespace ApplicationCore.Entities { public class RepositoryContext : DbContext { public RepositoryContext(DbContextOptions options) : base(options) { } public DbSet? PlayLists { get; set; } public DbSet? PlayListTracks { get; set; } public DbSet? Tracks { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<PlayListTrack>().HasKey(table => new {
table.PlayListId,
table.TrackId
});
}
}
} `
The PlaylistTrack entity display is fine, but missing edit button and if I press the Create button, an unhandled exception occurred: [image]https://user-images.githubusercontent.com/31003301/180617716-54a5c0e0-3bd3-4fe9-97a3-e0e0a8d9bbb6.png
— Reply to this email directly, view it on GitHubhttps://github.com/edandersen/core-admin/issues/74, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAEF6HEULOOMZS3MWX5TQPLVVQZG3ANCNFSM54OLJTPQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>
thanks you ,it is works now.
I using the chinook sample DB to trying core admin, the (PlaylistTrack) table reference to (PlayList) and (Track) tables, and I have check both of this table is work fine on core admin, And the DB schema:
The EntityClass:
The RepositoryContext class as well:
The PlaylistTrack entity display is fine, but missing edit button and if I press the Create button, an unhandled exception occurred:
I guess because the primary key contains multiple columns and Core Admin don't handle this key type?