-
Notifications
You must be signed in to change notification settings - Fork 224
Description
In my database, I have a table named PerformanceCode. This is a simple table with a few fields, and a primary key. I also have a stored procedure named ValidPerformanceCode.
In order to prevent another viewmodel, I use the configuration:
Settings.StoredProcedureReturnTypes.Add("ValidPerformanceCodes", "PerformanceCode");This generated the following code for the stored procedure (which is correct):
// dbo.ValidPerformanceCodes
public IQueryable<PerformanceCode> ValidPerformanceCodes(DateTime? fromDate, DateTime? toDate)
{
return Set<PerformanceCode>()
.FromSqlRaw("SELECT * FROM [dbo].[ValidPerformanceCodes]({0}, {1})", fromDate, toDate)
.AsNoTracking();
}It also generated the following configuration for the PerformanceCode table (which is also correct):
[GeneratedCode("EF.Reverse.POCO.Generator", "v3.6.0")]
// PerformanceCode
public partial class PerformanceCodeConfiguration : IEntityTypeConfiguration<PerformanceCode>
{
public void Configure(EntityTypeBuilder<PerformanceCode> builder)
{
builder.ToTable("PerformanceCode", "dbo");
builder.HasKey(x => x.Id).HasName("PK_PerformanceCode").IsClustered();
... rest omitted for brevityHowever, it will also generate the following line in the OnModelCreating method:
modelBuilder.Entity<PerformanceCode>().HasNoKey();The last line makes the application throw an exception, and it shouldn't be there.
For now, the workaround is to create partial class with custom configuration to disable the key first, and then add it again in OnModelCreatingPartial.
In my opinion, the HasNoKey line should only be created if the type is not already a known return type.