Skip to content

Shared-type entities (part of property bag entities) #9914

Description

@AndriySvyryd

There are entity types that don't have a natural mapping to a CLR type, either because they aren't part of the domain model (e.g. many-to-many join types) or because the CLR types are inaccessible (e.g. migration snapshot). While these could be mapped to shadow entity types #749 that would make working with them harder as they are tightly coupled to the state manager and would need special case handling throughout the stack, especially in the query pipeline.

Property bag entity types are still fully specified at model building time, dynamic types are tracked by #2282. The basic implementation would add support for entities backed up by a Dictionary<string, object> with a predefined entry that contains the entity type name.

Usage:

modelBuilder.Entity("Cat", c =>
    {
        c.Property<int>("Id");
        c.Property<string>("Name");
    });
context.Add(new Dictionary<string, object>
{
    { "Entity type name", "Cat" },
    { "Id", 123 },
    { "Name", "Tabby" }
});

Related to #2968

Activity

  1. ajcvickers commented on Oct 4, 2017

    @ajcvickers
    Contributor

    Putting this on the backlog for now; we may pull it in if it is needed for some other 2.1 feature, such as if we allow seeding using navigations.

  2. added this to the Backlog milestone on Oct 4, 2017
  3. dmitry-a-morozov commented on Oct 15, 2017

    @dmitry-a-morozov

    This issue seems like slight duplication of #2282. I would like repeat myself saying this feature will be very helpful to implement F# type provider for EF Core. Please, consider bumping up priority. Thanks.

  4. AndriySvyryd commented on Oct 15, 2017

    @AndriySvyryd
    MemberAuthor

    @dmitry-a-morozov #2282 is about property bag properties, but this one is about property bag entities, which might or might not contain property bag properties

  5. dmitry-a-morozov commented on Oct 15, 2017

    @dmitry-a-morozov

    @AndriySvyryd Thanks for clarification. I think I'm interested in this one then. I know statement about F# can be confusing. Let me know if you need more information on why it's helpful for F#.

  6. divega commented on Oct 16, 2017

    @divega
    Contributor

    @dmitry-a-morozov I believe this would be useful in combination with F# type providers because when the design-time generated types are erased, property bags could act as the runtime type. Is this what you had in mind?

    @AndriySvyryd when I wrote the text about property bags in #2282 I was specifically talking about "property bag entities":

    Property bags: Currently the EF Core stack assumes a distinct CLR type is mapped to each distinct entity type (and eventually for complex types) in the entity model and a CLR property for each entity property (minus any shadow property). This could be changed to enable EF to materialize and track simple property bags (e.g. any object that implements IDictionary<string, object> or contains an indexer property or any other mechanism to get and set values based on a property name). Even the name of the entity instance belongs to could become another property in the bag. This feature would make working with entity models that are created programmatically easier because it would remove the need to emit new CLR types for each entity and complex type at runtime.

    So I am still wondering what you mean when you say these are about two different things 😄

    Anyway, I think it is fine to track property bag entities separately here because #2282 is a meta-issue.

  7. dmitry-a-morozov commented on Oct 16, 2017

    @dmitry-a-morozov

    @divega Great ! I'm glad you're familiar with F# and we're on the same page.
    Once it's done F# community can start working on type providers for EF Core.

  8. dmitry-a-morozov commented on Oct 16, 2017

    @dmitry-a-morozov

    Also, consider working with IDictionary<string, object> interface as oppose to Dictionary<string, object> class so diff implementation can be supplied for example ExpandoObject.

  9. AndriySvyryd commented on Oct 16, 2017

    @AndriySvyryd
    MemberAuthor

    @divega @dmitry-a-morozov Oops, I was thinking about #2968

  10. divega commented on Oct 17, 2017

    @divega
    Contributor

    @AndriySvyryd makes sense. Yep, #2968 is closely related too.

    Also, consider working with IDictionary<string, object> interface as oppose to Dictionary<string, object> class...

    FWIW, I think it could be interesting to support arbitrary types that have an indexer of the right shape rather than requiring a specific type, i.e. pattern match the indexer, but not sure how much more complicated this would be.

  11. dmitry-a-morozov commented on Oct 19, 2017

    @dmitry-a-morozov

    @divega @AndriySvyryd Any chance you can consider this for 2.1?

  12. divega commented on Oct 19, 2017

    @divega
    Contributor

    @dmitry-a-morozov there is a possibility that we will do it in 2.1 or soon after, driven by other features like many-to-many without a join entity, but I wouldn't build plans around it just yet.

  13. cartermp commented on Jan 29, 2018

    @cartermp

    @divega since 2.1 is winding down, is this something we could get on the docket for 2.2?

  14. divega commented on Feb 12, 2018

    @divega
    Contributor

    @cartermp why don't we try to come up together with a plan to have EF Core work better with F#? Then we can use that to decide the priority of individual issues. I get how this one can help, however there is also #10731, which makes me wonder if we are missing the whole point 😄

  15. 62 remaining items

  16. modified the milestones: 5.0.0, on Jul 18, 2020
  17. modified the milestones: , on Aug 22, 2020
  18. modified the milestones: , 5.0.0 on Nov 7, 2020
  19. 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

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions