Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for owned entities #54

Open
Xriuk opened this issue Sep 26, 2022 · 4 comments
Open

Support for owned entities #54

Xriuk opened this issue Sep 26, 2022 · 4 comments

Comments

@Xriuk
Copy link

Xriuk commented Sep 26, 2022

I think this awesome library could support collection of owned entities, which get mapped to separate tables.
But I guess this would require some effort, because as of now all the triggers reference only generic types, and an owned type could have many underlying EF types, since it could be used in multiple entities.

I'm willing to help if you could guide me in what needs to be done in order to account for this.
I think that adding a reference to an EF entity would be enough, from there it could pick all the informations about the table, while all the generic methods would stay the same, since the columns are all the same.

@win7user10
Copy link
Owner

Hi, I think for each Action can be added an opportunity to pass a specific type for each trigger. It can have the next syntax

modelBuilder.Entity<Transaction>()
    .AfterUpdate(Action, typeof(DerivedTransaction))

This will require changes in the class EntityTypeBuilderExtensions to support passing the type, passing this parameter to each trigger builder
(namespace Laraue.EfCoreTriggers.Common.TriggerBuilders), e.g. for class OnDeleteTriggerDeleteAction and also modifying classes derived from BaseTriggerVisitor to use passed type if it specified otherwise type from the expression.

@Xriuk
Copy link
Author

Xriuk commented Sep 26, 2022

I'm not quite sure about the differences from EF and EF Core, in the latter the type of the entities in the model is IEntityType.
So this would require an additional property in ITrigger, and then the modifications you said, right?

@win7user10
Copy link
Owner

EF Core allows to retrieve information about any entity by its CLR type.
ITrigger already has a property TriggerEntityType. This property in the base implementation Trigger<TTriggerEntity> sets equal to the generic type of a trigger. All meta information (table name, column name etc) is extracting from this type. Constructor of this class could be extended to take the real type of the trigger (with the check that this type is derived from the generic type).

@Xriuk
Copy link
Author

Xriuk commented Sep 27, 2022

The problem is that owned entities are not mapped to a CLR type, for example an owned Category could belong to a Shop or a Blog, and thus being mapped to two different tables, while being a single CLR type.
So instead of using Type to create triggers maybe using IEntityType would be better because it would account for all the EF Core types, even many-to-many relationships mapped to a separate table, as well as owned entities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants