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

Fully implement entire entities in shadow state #749

Closed
ajcvickers opened this issue Oct 1, 2014 · 7 comments
Closed

Fully implement entire entities in shadow state #749

ajcvickers opened this issue Oct 1, 2014 · 7 comments
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. type-enhancement

Comments

@ajcvickers
Copy link
Contributor

That is, entities not backed by any CLR type. Also see #748.

@rjperes
Copy link

rjperes commented Feb 8, 2016

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! :-)

@divega
Copy link
Contributor

divega commented Feb 8, 2016

@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:

  1. The join entity in many-to-many associations (which you already mentioned)
  2. Extensibility scenarios in which collections of new data can be added to an entity (e.g. by a user) without having to define a new CLR type to store the new data.

In both cases not having a type in the domain model representing this data is a developer's choice.

@BradBarnich
Copy link

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 EnsureNoShadowEntities, but then it works.

@AndriySvyryd
Copy link
Member

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.

@ajcvickers
Copy link
Contributor Author

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.

@ajcvickers ajcvickers removed this from the Backlog milestone Feb 16, 2018
@lakeman
Copy link

lakeman commented Aug 16, 2018

It's a little silly that I need to define something like internal class Dummy<T>{} which I only intend to use for audit table migrations like the above example.

If you aren't going to implement shadow entities, then why not remove methods like IMutableModel.AddEntityType(string name), since their use isn't supported.

@AndriySvyryd
Copy link
Member

@lakeman Currently Migrations use shadow entity types to decouple the snapshot from the implementation.
When property bag entities are implemented AddEntityType(string name) will probably change meaning.

@ajcvickers ajcvickers added the closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. label Mar 10, 2022
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. type-enhancement
Projects
None yet
Development

No branches or pull requests

7 participants