Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow FK type in database to be different from PK type #29026

Merged
merged 2 commits into from
Sep 10, 2022

Conversation

ajcvickers
Copy link
Member

Approach uses built-in value converters to convert FK value to type of PK.

Fixes #28392


/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual IEqualityComparer<object?[]> EqualityComparer { get; }
public virtual IEqualityComparer<object?[]> EqualityComparer { get; set; } = null!;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public virtual IEqualityComparer<object?[]> EqualityComparer { get; set; } = null!;
public virtual IEqualityComparer<object?[]> EqualityComparer { get; protected set; } = null!;

Good candidate to use required

Comment on lines 95 to 96
IReadOnlyModificationCommand command,
bool fromOriginalValues,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding work for the next cleanup, I see 🤔

}
catch (TargetInvocationException exception)
{
throw exception.InnerException ?? exception;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the users hit this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but is is rare; see tests. This would happen when using SaveChanges with store types for which we can't convert values. So, for example, and int and a GUID. But its hard to imagine a sane use of relationships, even without constraints in the database, that would get here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not worth it to add the try just to make the exception a bit better

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will remove.


using System.Transactions;

namespace Microsoft.EntityFrameworkCore;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move it under .Update

Approach uses built-in value converters to convert FK value to type of PK.

Fixes #28392
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

foreign key generation not working on 7.x builds, works on 6.x
2 participants