Skip to content

AlternateKeysODataUriResolver does not support null keys #3415

Open

Description

@Xriuk

AlternateKeysODataUriResolver does not support null key values

Is there a reason for this? I have an entity which has a unique index over 2 string properties, one of which can be also null.

Activity

  1. xuzhg commented on Nov 4, 2025

    @xuzhg
    Contributor

    @Xriuk From OData perspective, key is non-nullable.
    For the alternate key, I think you raised a good question. The current implementation, I think, is following up the OData key rule. But, it seems there's no "clear" rules for alternate key.
    For example:

    1. the property for alternate key should be 'non-nullable'? So far, there's no such check.
    2. what's the logic if the alternate key value is null for multiple entities?
  2. Xriuk commented on Nov 4, 2025

    @Xriuk
    Author

    I think nullable properties should be allowed, because null can be a valid value as any other, so the key should work regardless. In SQL there are filters to filter out null values when needed, eg, my alternate key in the example is something like this:

    // If null the entity has no alt key
    public string? AltKey1 { get; set; }
    
    // Can be null, can be not null only if AltKey1 is not null
    public string? AltKey2 { get; set; }

    And in the db there is a filter:

    AltKey1 IS NOT NULL
    

    So both properties are nullable in the model, but in the alt key only one of them, I think adding a IsNullable prop (or even a filter-like method, but that would be more complex) would help.
    The ideal would be to mirror SQL unique indexes, as they are very flexible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions