Skip to content

EF7 override Identity nullable columns. #48325

@urielzen

Description

@urielzen

We have a project with nullable errors enabled, and we just recently upgraded from EF6 to EF7 and that uncovered some nullable errors in our code around Identity properties. Email for example is nullable in the Microsoft.AspNetCore.Identity.IdentityUser class

public class IdentityUser<TKey> where TKey : IEquatable<TKey>
{
    /// <summary>
    /// Gets or sets the email address for this user.
    /// </summary>
    [ProtectedPersonalData]
    public virtual string? Email { get; set; }

We would like to keep the email required/not nullable, so we don't have to refactor the thousand places in our code that are giving us errors because Email now is suddenly nullable. But if I try to override the nullability for the property in my ApplicationUser class, I get an error

public partial class ApplicationUser : IdentityUser<string>
{
    public override string Email { get; set; } = null!;
CS8765 - Nullability of type of parameter 'value' doesn't match overridden member (possibly because of nullability attributes).

I guess we can add the thousand null checks in our code where we have the errors, but we would very much like another easier to implement approach if possible.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-identityIncludes: Identity and providers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions