Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Foreign key crashes when reference is on the derived table #212

Closed
mciprijanovic opened this issue Aug 28, 2020 · 2 comments
Closed

Foreign key crashes when reference is on the derived table #212

mciprijanovic opened this issue Aug 28, 2020 · 2 comments
Labels
bug Confirmed bug released Issue is resolved in a current release
Projects
Milestone

Comments

@mciprijanovic
Copy link

When you have model that contains one base entity and 2 derived entities (example: WorkItem as a base entity and RemediationTicket and CAPA as derived entities) and then you try to set relation one to many between derived entities, designer generates he following code in dbContext OnModelCreating method:

modelBuilder.Entity<global::Novolyze.Ticketing.Services.Model.Capa>() .HasOne(x => x.RemediationTicket) .WithMany(x => x.Capas) .HasForeignKey();

HasForeignKey() crashes at runtime since it must have FK name. As I can see, the issue is probably because FK name is constructed by the designer by concatenating relation name and Id field, but in this case Id field does not exist in derived entity but in the base one. So, in this case method: .HasForeignKey("RemediationTicket_Id") should be generated, but obviously designer does not know to do that.

I tried various workarounds but didn't find the appropriate one. I can add key name manually, but designer will overwrite it on every change. Can this bug be fixed?

@msawczyn msawczyn added the bug Confirmed bug label Aug 28, 2020
@msawczyn msawczyn added this to Enhancement Requests in EFDesigner via automation Aug 28, 2020
@msawczyn msawczyn moved this from Enhancement Requests to Bug Reports in EFDesigner Aug 28, 2020
@msawczyn
Copy link
Owner

Absolutely. I'll try to get to that today. Thanks for the report.

@mciprijanovic
Copy link
Author

Thanks for ultra quick response. When can we expect fix to be in production?

@msawczyn msawczyn added this to the 2.0.5.5 milestone Aug 31, 2020
@msawczyn msawczyn added the released Issue is resolved in a current release label Aug 31, 2020
@msawczyn msawczyn moved this from Bug Reports to Done in EFDesigner Aug 31, 2020
@msawczyn msawczyn closed this as completed Sep 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Confirmed bug released Issue is resolved in a current release
Projects
EFDesigner
  
Done
Development

No branches or pull requests

2 participants