Skip to content

Dynamic properties with DerivesFrom is not working #2747

Open
@komdil

Description

@komdil

I am having problem with a dynamic properties. It looks like it is not working with multiple inheritance. OData is not seeing dynamic properties from the base class.

Assemblies affected

Microsoft.AspNetCore.OData 8.0.11

Reproduce steps

Currently my model classes looks like this:

    public class Laptop : Product
    {
        public decimal Price { get; set; }
        public string Manufacturer { get; set; }
        public int Ram { get; set; }
        public string CPU { get; set; }
        public int HardDrive { get; set; }
    }

    public class ProductBase : ServerEntityBase
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
    }

    public class Product : ProductBase
    {
        public string Description { get; set; }
    }

    public abstract class ServerEntityBase
    {
        [NotMapped]
        public virtual IDictionary<string, object> Properties { get; set; }

        public ServerEntityBase()
        {

            Properties = new Dictionary<string, object>()
            {
                { "MySuperProperty","MySuperValue" }
            };
        }
    }

And my configuration:

        IEdmModel GetEdmModel()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            ProductBaseMapping(builder);
            ProductMapping(builder);
            LaptopMapping(builder);
            return builder.GetEdmModel();
        }

        void ProductBaseMapping(ODataConventionModelBuilder builder)
        {
            builder.EntityType<ProductBase>();
            builder.EntitySet<ProductBase>("ProductBase");
        }

        void ProductMapping(ODataConventionModelBuilder builder)
        {
            builder.EntityType<Product>().DerivesFrom<ProductBase>();
            builder.EntitySet<Product>("Product");
        }

        void LaptopMapping(ODataConventionModelBuilder builder)
        {
            builder.EntityType<Laptop>().DerivesFrom<Product>();
            builder.EntitySet<Laptop>("Laptop");
        }

I am sending request for 3 routes:
https://localhost:7258/api/odata/productbase?$select=MySuperProperty
https://localhost:7258/api/odata/product?$select=MySuperProperty
https://localhost:7258/api/odata/laptop?$select=MySuperProperty

Expected result

I think it should work

Actual result

I am getting error: Could not find a property named 'MySuperProperty' on type [MyType]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions