0

I have a less than ideal data model that is something like this (a country can have no or exactly one central bank):

Table COUNTRY:
COUNTRY_ID: Guid

Table CENTRAL_BANK:
CENTRAL_BANK_ID: Guid
COUNTRY_ID: Guid

Of course it would be better if we head a CENTRAL_BANK_ID in the COUNTRY table, then it would probably work as intended. But now we get something like:

class Country
{
    public Guid CountryId { get; set; }
    public virtual ICollection<CentralBank> CentralBanks { get; set; }
}

But what we want is of course:

class Country
{
    public Guid CountryId { get; set; }
    public virtual CentralBank? CentralBank { get; set; }
}

Is there some way to tell the EF Core Power Tools that the relationship is really 1:0..1 and not 1:N?

TravelingFox
  • 484
  • 5
  • 18
  • 1
    The problem is, it *is* a 1:n relationship in the database. It's not if `CENTRAL_BANK.COUNTRY_ID` has a unique index, making it an alternate key. I don't know if power tools pick that up. – Gert Arnold Feb 20 '23 at 13:00
  • @GertArnold Yes, obviously, the data model is broken and I'm trying to change it. But until that's done, it would be great to have a workaround. – TravelingFox Feb 20 '23 at 14:19
  • What I'm trying to say is: EFCPT won't recognize it as 1:1. Since there's no option to configure individual relationships you'll always have to customize the generated code. – Gert Arnold Feb 20 '23 at 15:25

0 Answers0