Skip to content

Fully implement entire entities in shadow state #749

Closed as not planned
Closed as not planned

Description

@ajcvickers

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

Activity

  1. added this to the Backlog milestone on Oct 10, 2014
  2. rjperes commented on Feb 8, 2016

    @rjperes

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

  3. divega commented on Feb 8, 2016

    @divega
    Contributor

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

  4. BradBarnich commented on Apr 13, 2017

    @BradBarnich

    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.

  5. modified the milestones: Backlog, 2.1.0 on Sep 22, 2017
  6. self-assigned this
    on Sep 22, 2017
  7. AndriySvyryd commented on Sep 27, 2017

    @AndriySvyryd
    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.

  8. removed their assignment
    on Sep 27, 2017
  9. modified the milestones: 2.1.0, Backlog on Sep 27, 2017
  10. ajcvickers commented on Feb 16, 2018

    @ajcvickers
    ContributorAuthor

    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.

  11. removed this from the Backlog milestone on Feb 16, 2018
  12. lakeman commented on Aug 16, 2018

    @lakeman

    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.

  13. AndriySvyryd commented on Aug 16, 2018

    @AndriySvyryd
    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.

  14. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions