OData / ModelBuilder

A project to generate Edm (Entity Data Model) from CLR types
19 stars 19 forks source link

Capabilities vocabulary ignored when using composite key #38

Open rpallares opened 1 year ago

rpallares commented 1 year ago

[Capabilities vocabulary support(https://learn.microsoft.com/en-us/odata/webapi/capabilities-vocabulary-support) is working well for an entity until we use Key value binding

Assemblies affected

Reproduce steps

public class MyEntity
{
    public Guid Id { get; set; }

    [Required]
    [NotSortable]
    [NotFilterable]
    public required string SomeStringKey { get; set; }
}

private IEdmModel BuildModel()
{
    var builder = new ODataConventionModelBuilder();
    var entitySetConfiguration = builder.EntitySet<MyEntity>(nameof(MyEntity));

    // If this line is present FilterRestrictions and SortRestrictions are removed from metadata.xml
    entitySetConfiguration.EntityType.HasKey(e => new { e.SomeStringKey, e.Id });

    return builder.GetEdmModel();
}

Expected result

Capabilities annotations should be declared whatever the entity key definition

Actual result

Capabilities annotations are ignored if the entity declare a composite

Additional detail

This may be related to #10, but I'm not sure if #10 is just obsolete or not

habbes commented 1 year ago

This appears to be a feature gap. But it may be possible to achieve what you're looking for by using the capability annotations extension methods available in the library. It provides fluent APIs for configuration capability restrictions. Check the documentation here: https://learn.microsoft.com/en-us/odata/webapi/model-builder-capabilities-vocabulary