You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In EF Core 6.0 new EntityTypeConfiguration attribute was introduced. It's handy very much. Now it's possible to move configuration logic into another file in the same project or even into another assembly. But there's one problem with it.
Say, we have simple entity class and configuration for this entity.
The problem with EntityTypeConfiguration is that at compile time there's no check for the type used as argument for it. It means I can write the following, which will compile fine but will generate exception at run time:
In EF Core 6.0 new EntityTypeConfiguration attribute was introduced. It's handy very much. Now it's possible to move configuration logic into another file in the same project or even into another assembly. But there's one problem with it.
Say, we have simple entity class and configuration for this entity.
The problem with
EntityTypeConfiguration
is that at compile time there's no check for the type used as argument for it. It means I can write the following, which will compile fine but will generate exception at run time:Since C#11 it's possible to use generic attributes. For
EntityTypeConfiguration
it means that we could write the following:The advantage is that we now can have type constraint:
If class does not implement
IEntityTypeConfiguration<>
, then code won't compile the code and IDE will show red squiggles.The text was updated successfully, but these errors were encountered: