I am using Sitecore Commerce Experience 9 update-2, and want to add a custom child component to an entity.
The Sitecore.Commerce.Core.Component
has a Key
annotation (of type System.ComponentModel.DataAnnotations
).
namespace Sitecore.Commerce.Core
{
public class Component
{
...
[Key]
public string Id { get; set; }
..
}
}
This key annotation makes OData to generate a EntityType
for components (or sub-classes of Component
, e.g. CustomComponent
).
<EntityType Name="CustomComponent" BaseType="Sitecore.Commerce.Core.Component">
<Property Name="FirstName" Type="Edm.String" />
</EntityType>
OData generates a NavigationProperty
for entity types, for example:
<NavigationProperty Name="Components" Type="Collection(CustomComponent)" />
Navigation properties are by default not handled by the OData server.
Result of this is that child components (ChildComponents
property on the Component
class) cannot be easily added using the OOTB command controllers.
Only solution found so far is to implement a custom controller and method that adds a child component for a certain entity (e.g. an AddChildComponentToCart
CommandController
method).
Are there any other (cleaner, simpler) ways to add child components to an entity?
Any good reasons why a Component
is not an OData complex type (this could be achieved by not having the [Key]
annotation on the Component
class)?