-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fully implement entire entities in shadow state #749
Comments
May I ask what is the gain of this? Does this feature exist in any ORM? I know this is going to be used for M:M mapping in EF Core, but other that that, I honestly can't see the point. Thanks! :-) |
@rjperes In general we use shadow sate to reduce the coupling between the domain model the application reasons about and the extra information EF Core might need to track and reason about. This allows for more flexibility on the shape of the types while maintaining how EF Core reasons about the model at runtime relatively simple and based on a relatively small number of different concepts. For individual properties in shadow state one of the main examples is how EF Core always reasons about relationships between objects in terms of foreign key properties, but CLR types that participate in those relationships don't need to contain the FKs. For full entities in shadow state, the main two potential scenarios to come to mind are:
In both cases not having a type in the domain model representing this data is a developer's choice. |
for my use case, I have audit tables that are maintained by trigger. I wanted the tables to be part of migrations so I did this: foreach ( var entityType in modelBuilder.Model.GetEntityTypes().ToArray() )
{
var auditEntity = modelBuilder.Entity( entityType.Relational().TableName + "History" );
foreach ( var property in entityType.GetProperties() )
{
auditEntity.Property( property.ClrType, property.Name );
}
auditEntity.Property( typeof( DateTime ), "ValidTo" );
auditEntity.HasKey( "ID", "ValidTo" );
} Also had to make a custom model validator that skips |
We should completely drop support for shadow state entities in favor of property bag entities #9914 as they are easier to work with as a customer and would require less code changes to implement. |
Closing as this particular idea (entities without any CLR object) may now not be needed since something like property bags (or even object entities with shadow properties) would cover the cases where this was thought to be useful. |
It's a little silly that I need to define something like If you aren't going to implement shadow entities, then why not remove methods like |
@lakeman Currently Migrations use shadow entity types to decouple the snapshot from the implementation. |
That is, entities not backed by any CLR type. Also see #748.
The text was updated successfully, but these errors were encountered: