efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Add Generic version of EntityTypeConfiguration Attribute

Open saivineeth100 opened this issue 2 years ago • 2 comments

Add generic arguments support for EntityTypeConfiguration attribute

From

[EntityTypeConfiguration(typeof(ModelConfiguration))]
    public class Model
    {.....}

To

[EntityTypeConfiguration<ModelConfiguration>()]
    public class Model
    {.....}

saivineeth100 avatar Jan 15 '23 13:01 saivineeth100

Should we extend EntityTypeConfigurationEntityTypeAttributeConvention with the new EntityTypeConfigurationAttribute<T> or create a new one?

Marusyk avatar Jan 22 '23 17:01 Marusyk

@Marusyk Probably extend, unless that doesn't work very well.

ajcvickers avatar Jan 25 '23 22:01 ajcvickers

Is this one up for grabs?

joelmandell avatar Feb 11 '23 06:02 joelmandell

@joelmandell Yes.

ajcvickers avatar Feb 11 '23 11:02 ajcvickers

Useful feature for DDD when parent class is generic Entity or AggregateEntity

amyboose avatar Mar 16 '23 14:03 amyboose

In order to add generic constraint as the below should we move IEntityTypeConfiguration from EFCore to the abstraction project , since the type EntityTypeConfigurationAttribute exists in EFCore.Abstractions project , or we move the generic implementation to the EFCore project fix

where TEntity : IEntityTypeConfiguration

OsamaAbuSitta avatar Apr 02 '23 12:04 OsamaAbuSitta

@OsamaAbuSitta We will discuss. The problem is that IEntityTypeConfiguration has other dependencies that we cannot move. We may not be able to add a constraint to the generic argument.

ajcvickers avatar Apr 04 '23 11:04 ajcvickers

@ajcvickers , In that case, should I proceed with submitting the pull request? for this changes commit

OsamaAbuSitta avatar Apr 06 '23 06:04 OsamaAbuSitta

@OsamaAbuSitta We discussed this and we think its reasonable to put the generic version in the EntityFramework.Core assembly. (It was pointed out that in other to use this, there would already need to be a reference from the assembly containing the entity types to the assembly containing the configuration, which in turn must reference the main EF assembly, so we don't actually gain anything here by putting it in Abstractions.)

Also, leave the existing non-generic class where it is.

ajcvickers avatar Apr 06 '23 10:04 ajcvickers