I'm trying to use OData in my project.
I have this class JournalCopy which has ICollection<JournalItemCopy> Items property. I tried to get this Items through JournalCopy and I want to use OData for filtering and expanding the results.
Here is my action:
[ODataRoutePrefix("JournalRepetitives")]
[Authorize(AuthenticationSchemes = TenantRequired.DefaultSchemeName)]
public class JournalRepetitivesController : ODataController
{
private readonly ReadModelContext _readModelContext;
public JournalRepetitivesController(ReadModelContext readModelContext)
{
_readModelContext = readModelContext;
}
private IQueryable<JournalCopy> JournalCopyQuery() => _readModelContext.Set<JournalCopy>();
[EnableQuery]
[HttpGet]
[ODataRoute("GetItems(Id={id})")]
public IQueryable<JournalItemCopy> GetItems([FromODataUri] string id)
{
return JournalCopyQuery().Where(e => e.Id == id)
.SelectMany(e => e.Items);
}
}
and I have this configuration:
public static class ReadModelConfiguration
{
public static ODataModelBuilder Configure()
{
var builder = new ODataConventionModelBuilder();
builder.EntityType<JournalCopy>().HasKey(e => e.Id);
builder.EntityType<JournalItemCopy>().Collection.Function("GetItems")
.ReturnsCollectionFromEntitySet<JournalItemCopy>(nameof(JournalItemCopy))
.Parameter<string>("Id").Required();
}
}
So when I am using http://localhost:8000/v2/JournalRepetitives/GetItems(Id='76dee73f-8cd4-4311-9708-4701c3d2d017') to call the Api in postman but I got The path template 'JournalRepetitives/GetItems(Id={id})' on the action 'GetItems' in controller 'JournalRepetitives' is not a valid OData path template. Key template value 'GetItems(Id={id})' for key segment 'id' does not start with '{' or ends with '}'. but I don't know its problem.
Any Idea how can I fix it?

