Open TARGAZ opened 2 months ago
On a entity with a complex property that has dynamic property dictionary.
Would you mind sharing a sample of what that model looks like as well?
You can find the EDM model here : https://github.com/TARGAZ/ODataSelectDynamicPropertyBug/blob/main/Program.cs
var modelBuilder = new ODataModelBuilder();
var customerType = modelBuilder.EntityType<Customer>();
customerType.HasKey(c => c.Id);
customerType.ComplexProperty(c => c.Name);
Type localizableStringType = typeof(LocalizableString);
ComplexTypeConfiguration localizableStringConfiguration = modelBuilder.AddComplexType(localizableStringType);
localizableStringConfiguration.AddDynamicPropertyDictionary(localizableStringType.GetProperty(nameof(LocalizableString.ExtendedProperties)));
modelBuilder.EntitySet<Customer>("Customers");
Oh I'm dumb, I didn't realize you provided a sample repo there, my bad @TARGAZ .
Based on your code..... can you check whether replacing IDictionary
on the ExtendedProperties
property with Dictionary
(the concrete class) makes a difference here?
public Dictionary<string, object> ExtendedProperties
IIRC, OData's EDM builder won't automatically match interfaces to implementations when they are found in the model. You either need to specify the type explicitly in that case, or just type it to the concrete type and it will be picked up automatically.
Let us know if that changes the error in any way.
Unfortunately, this doesn't work I have the same error. Note that the $filter works on this property.
@TARGAZ OData needs the 'model type' as POCO class, so your 'LocalizableString' can't be treated correctly since it's derived from 'ReadOnlyDictionary< >'.
If you replace your 'LocalizableString' definition using composition, not using inheritance, it should work:
public sealed class LocalizableString/* : ReadOnlyDictionary<string, string>*/
{
private IDictionary<string, object> _values;
......
}
Hello, Thank you for your help. It works really well :).
Hello,
On a entity with a complex property that has dynamic property dictionary. I can't do a select clause on this complex property.
Assemblies affected Microsoft.AspNetCore.OData 8.2.5
Reproduce steps 1.Clone the repository : https://github.com/TARGAZ/ODataSelectDynamicPropertyBug 2.Run 3.Try queries :
Expected result First query : https://localhost:7092/odata/customers?$select=Name
Second Query : https://localhost:7092/odata/customers?$select=Name/en
Actual result The error is the same for both queries :
Stack trace :