IENumerable vs OdataEnumerable

I cannot find why one is accepted as IEnumerable and the other not.
Products is accepted but Recipe gives the error: Error CS0266 :
.... An explicit conversion exists (are you missing a cast?)

   protected IEnumerable<Recipe> recipes;
    protected IEnumerable<Product> products;

    protected override async Task OnInitializedAsync()
    {
        var resultRecipes = await PiConService.GetRecipes();
        recipes = resultRecipes.Value.AsODataEnumerable();

        var resultProducts = await PiConService.GetProducts();
        products = resultProducts.Value.AsODataEnumerable();
    }

But when I change the IENumerable in the OdataEnumerable, the error is gone, but then the DataGrid will not except this as DATA. Also the generic type has to be changed... See below.

    protected ODataEnumerable<Server.Models.PiCon.Recipe> recipes;
    protected IEnumerable<Product> products;

    protected override async Task OnInitializedAsync()
    {
        var resultRecipes = await PiConService.GetRecipes();
        recipes = resultRecipes.Value.AsODataEnumerable();

        var resultProducts = await PiConService.GetProducts();
        products = resultProducts.Value.AsODataEnumerable();
    }

Both product and recipe are database items and added bij Radzen Database features.

1 Like

ODataEnumerable is used to tell the DataGrid to use OData filtering, sorting and paging expressions.

But why is Products accept the IEnumable and the Recipe not.
The OdataEnumerable is not valid for : Data ="@recipe", withTItem="Recipe".

@enchev
The problem will not go away,
In de grid.razor.cs the assignment of the field is :
protected IEnumerable<Server.Models.PiCon.Recipe> recipes;

the the grid.razor will not accept these and wants an assignment of the field:
protected IEnumerable<Recipe> recipes;

but then the grid.razor.cs is complaining..... about the assignment.
both assignments should be correct because the Recipe is in the folder and namespace .Server.Models.PiCon.Recipe

the part in grid.razor.cs:

var resultRecipes = await PiConService.GetRecipes();
 recipes = resultRecipes.Value.AsEnumerable();

the part in grid.razor

 <RadzenDataGrid @ref="gridRecipes"
                    Loc="@Localizer"
                    TItem="Recipe"
                    name="Recipe"
                    Data="@recipes"
                    RowExpand="@RecipeRowExpand"

There is probably another type called Recipe in scope (maybe a page called Recipe.razor).

Yes, the page name is the same, but on other pages it's not a problem.
There is no other Recipe.cs.
Used is

Recipe.cs   - Model
Recipe.razor   - the Razor design
Recipe.Razor.cs - the code part of the design.
<RadzenPanelMenuItem Text="Recipe" Path="recipe" /> - pagename

This is how C# works - it picks the closest type with the same name in scope. This is why you have to use fully qualified types Server.Models.PiCon.Recipe instead of just Recipe.

You're right, just overlooked it.
The pages Class is of course also Recipe, i will change it.

Thanks.