Home

Linq Query: InvalidOperationException: The relationship ... because it is not compatible. Configure

I have a database. This database schema is in use for various apps among others .net core apps with EF core

I had a problem with a Linq Query so I thought I'd try to play with this in Linqpad, however:

  • I make a new entity framework core connection in LinqPad
  • Release 5.0.7
  • Connect

Then ... any query complains about an invalid FK

  • I have a table which has a PK of (int, string, int)
  • another table references this with FK int, string, nullable(int) .

I think it complains about the nullable FK key and that this is an incompatible foreign key. So I assume that when you run "any query" it does some validation on the schema overall to start with.

How do I solve this? (it is impossible to change the schema of the database)

Comments

  • edited September 2021

    I looked further into this . It seems that it is complaining about 1 specific table which has about 25 Foreign key relations. EF core generator / sql server seem to complain not about anything.

    So there must be somewhere a problem with that specific table. But no clue.

    CONSTRAINT [PK_SysCalculation] PRIMARY KEY CLUSTERED
    (
    [CustomerId] ASC,
    [CalculationTypeId] ASC,
    [Id] ASC
    )

    which is int, int, nvarchar(10)

    A foreign key example is

    FOREIGN KEY([CustomerId], [CalculationTypeId], [CalculationId]) REFERENCES [SysCalculation]
    ([CustomerId], [CalculationTypeId], [Id])

    which is exactly this int, int, nvarchar(10) >> int, int, nvarchar(10)

    Hmm

  • edited September 2021

    EF Core Utils imports everything Ok. So it is only Linqpad that reports this problem.

    Could it be that it sets the keys in the wrong order , that there is a bug in this?

    So that instead of (1,2,3) => (1,2,3) it makes it somehow (1,3,2) => (1,2,3) ?

  • edited September 2021

    Found the solution:

    • When i rename the column holding the primary key from "calculationtypeid" TO "enumcalculationtypeid"... the problem is resolved.

    ...................... so whatever ordens those keys needs an update. because if it is done based on naming this can go wrong a million times.

Sign In or Register to comment.