Closed AaronSadlerUK closed 6 months ago
Can you explain the use case?
Currently we limit the picker to root level collections as child collections require some knowledge of the parent collection so we just haven't contemplated the best way of achieving this. Some valid use cases would be useful to evaluate the best approach.
Sure thing.
In this case I have a Parent collection of "Client Service Details"
This has smaller sub collections of "MailGunDetails", "CloudflareDetails", "MSSQLDetails"
Currently I need to write a whole service to return these items, when really I should be able to return the child collection from the entity picker.
E.g.
var currentMember = _memberManager.AsPublishedMember(await _memberManager.GetCurrentMemberAsync()) as MemberType;
foreach (var serviceDetail in currentMember.ServiceDetails)
{
...
foreach (var childCollectionItem in serviceDetail.ChildCollectionName)
{
...
}
}
Ok, so it's not that you want to pick the child collection entities, rather you want to itterate a child collection from it's parent.
Hmmm, the main problem here really is that we don't have control of the entity type as these are your strongly defined models. Now, you could have a collection property on your model that either somehow via Konstrukt populates for you but we don't currently have this. But, I believe this should be possible using NPoco attributes to map and fetch child entities. It might be worth taking a look at that.
I will have a think on how this could work though 🤔
I'm thinking the easiest implementation could be an extension on the entity property say .GetChildCollection(object parentId)
where it gets all the child collections based on the parentid specified, then using an as Type
cast it can be cast in my code (much like what I have to do with the member properties in my example)
Removing the need for a whole service and having it returned on the entity property would make life simpler
Sure, but unless we define GetChildCollection
as an extension method on object
we couldn't define it because you supply the type. The only thing we could do is expose some method on say the KonstruktRepositoryFactory that lets you get a child collection:
_konstruktRepository.GetChildCollection<Person, int>(parentEntity.Id, "collectionAlias");
Yeah something like that could work, let me know if you/when you need something tested 👍
Describe the bug When accessing a property configured using the Entity Picker Value Converter, the Child Collections are missing.
Expected behavior The child collections to be accessible when using the Value Converter.
This item has been added to our backlog AB#34772