How do you expose a property on a class that has a protected or private Setter with the EDMBuilder for .Net Core 3.1 OData.
For example:
public class Person
{
public int Id { get; set; }
public string Name { get; protected set; }
}
public class SomeClassToBuildEdmModel
{
public static IEdmModel GetEdmModel( IServiceProvider serviceProvider )
{
var builder = new ODataConventionModelBuilder( serviceProvider );
builder.EntitySet<Person>(nameof(Person)).EntityType.HasKey( e => e.Id );
}
}
Performing a Get on the endpoint will only retrieve Id, not Name. The builder ignores any property that has a private or protected setter.
How do I override this or expose the property without removing the protected access modifier?
I did find this link: Old Solution to the Problem
But since this answer is 2 years old, I was hoping for a more elegant or easier solution.
Update: I added:
public class SomeClassToBuildEdmModel
{
public static IEdmModel GetEdmModel( IServiceProvider serviceProvider )
{
var builder = new ODataConventionModelBuilder( serviceProvider );
var personConfig = builder.EntityType<Person>();
personConfig.HasKey( e => e.PersonId );
**personConfig.Property( e => e.Name ).IsOptional();**
builder.EntitySet<Person>(nameof(Person));
}
}
This seems to work. However, it seems hinky... is there a better way?