Closed axel-habermaier closed 4 years ago
@axel-habermaier You need to be very careful doing any custom equality on entity types for two reasons:
Leaving this open for now in case @divega @anpete or @smitpatel want to comment more.
@ajcvickers: Thanks for your response. I understand that overloading equality is problematic and I don't really want to use it. However, I stumbled across this seemingly inconsistent behaviour of one-to-one and many-to-one relationships that happens to involve overloaded equality operators. So this issue is a suggestion to improve this inconsistency rather than allowing custom equality.
@axel-habermaier I'm not sure how we would improve it, but leaving it open for ideas from others.
This works in 3.1 without any exceptions.
I stumbled across a surprising inconsistency between one-to-one and one-to-many relationships in conjunction with an overloaded
operator !=
. I would not expect the following code to work - at the very least, however, I would not expect to find a difference between the arity of relationships.Steps to reproduce
.csproj
file:Replace the generated
Program.cs
with the following code:Now add the following code to the
Base
class:Expected behavior
Either both queries should result in the exception, or both should work. However, I don't really see how custom equality operators should be supported by SQL translator, hence I would assume that both queries should throw.
Actual behavior
Only the one-to-many relationship throws. The one-to-one relationship probably ignores the custom
operator !=
.Further technical details
EF Core version: 1.1.2 Database Provider: both SqlServer and InMemory Operating system: Win10, x64 IDE: VS 2017.02