0
I use GraphQl to fetch the data, here is my method in order to get the result based on category ID.
public IQueryable<Product> GetActiveProducts( string categoryId, CancellationToken cancellationToken )
=>
return _dDbContext.Categories.Where(x => x.Id == categoryId);
Also, my entity is as follows:
public class Category:IEntityHierarchy
{
public string Id { get; set; }
// code removed for brevity
and also IEntityHierarchy
public class IEntityHierarchy
{
public string Id { get; set; }
}
The configuration of my category entity is:
builder.Property( x => x.Id )
.HasConversion(
v =>HierarchyId.Parse( v ),
v => v.ToString() ) ;
When I call the endpoint, it throws an error: Invalid cast from ‘System.String’ to ‘Microsoft.EntityFrameworkCore.HierarchyId
And here is also my query:
query($categoryId:String!){
activeProducts(categoryId:$categoryId)
{
id
name
}
}
// and query valiables
{
"categoryId":"/2/7/"
}
I also should mention that when I directly provide the category ID in my Linq query, it works.
public IQueryable<Product> GetActiveProducts( string categoryId, CancellationToken cancellationToken )
=>
return _dDbContext.Categories.Where(x =>x.Id == "/2/7/");