IntentArchitect / Support

A repository dedicated to handling issues and support queries
3 stars 0 forks source link

Bug/Feature: Application DB Context and Owned entities #78

Closed shainegordon closed 1 year ago

shainegordon commented 1 year ago

What happened?

This is another where it's either a bug or a feature request.

If you have an owned entity, that entity won't appear on the ApplicationDbContext

Steps to reproduce:

image

If you now run the software factory, you will see that only Parent gets added to ApplicationDbContext and IApplicationDbContext.

What version of Intent Architect are you using?

4.0.6

Additional information

I understand why this happens - Another entity owns the entity, so you should access it via the aggregate root/repository. That is why NOT exposing a repository for Child 100% makes sense.

IMO, this rule should not apply to the ApplicationDbContext. There are cases, e.g. reporting, which I as a developer would like to be able to construct my own queries, regardless of the domain rules.

joelsteventurner commented 1 year ago

Hi @shainegordon

I've added a ticket for our team to discuss this, I know we have a similar pattern in the repository space where you can opt into repositories for non-aggregates when required.

Which approach do you think would be better to solve your requirement? a) Adding all non-aggregate entities to the DBContext b) white-listing non-aggregate entities to be added to the DBContext (through a stereotype)

shainegordon commented 1 year ago

I think this should be a module-level setting.

The "issue" I see with a stereotype, is that you can put this stereotype on a parent/single class, which doesn't really make sense.

joelsteventurner commented 1 year ago

This option would definitely be behind a module setting for backwards compatibility and we can definitely take a look some validations on the Stereotype for where it can be applied, my question was more around the idea that some aggregate roots can have deep hierarchies.

In which case would you want all those children added to the DBContext?

shainegordon commented 1 year ago

I think every "table"/class should be on the db context

joelsteventurner commented 1 year ago

As per our discussion yesterday, after some investigation, you can apply the table stereo type to these domain entities which, will add the Entity to your DB Context. Note if you are dealing with compositional entities that they will no longer be set up with an "Has" rather than "Owns" an mapping.