Manage keyless table / entity with EF core 6 / OData

Viewed 51

I have a keyless data type I want to store in a table and manage using an API controller. However, an error is thrown in GetEdmModel:

Odata validation error

[Keyless]
public class UserDocuments
{
    [StringLength(30)]
    public string UserID { get; set; } = string.Empty;
    public Guid DocumentID { get; set; } = Guid.Empty;
    public int Version { get; set; } = -1;  
}

public static IEdmModel GetEdmModel()
{    
    ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
    builder.EntitySet<UserDocuments>("UserDocuments");
    return builder.GetEdmModel();
}

I also tried this:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<UserDocuments>()
        .HasNoKey()
        .ToTable("UserDocuments");
    base.OnModelCreating(modelBuilder);
}

but it didn't work either; And as far as I have understood it this is equivalent to using the [Keyless] annotation for class UserDocuments.

So how do I need to implement this to get the functionality I want?

0 Answers
Related