Shared-type entities (part of property bag entities)

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:12
  • Comments:21 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
AndriySvyrydcommented, Jul 15, 2020

Design meeting decisions:

  • Rename Entity(string, Type) to SharedEntity(string, Type)
  • Add SharedEntity(Type) that just marks the type as shared without creating any entity types. Removes entity types created by convention, throws for entity types configured explicitly
  • Don’t add relationship APIs with name and lambda or name and type for now
  • UsingEntity will only create a STET if the CLR type is marked as shared
1reaction
smitpatelcommented, Jun 4, 2020

Notes from today’s design meeting regarding relationship APIs for shared type entity types.

  • string based APIs should not require any changes. The name of entity type should be unique identifier to get the entity type so shared type entities should work same as how shadow entities would work.
  • Lambda based APIs would take string argument which is name of the entity type.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Shadow and Indexer Properties - EF Core
Entity types that contain only indexer properties are known as property bag entity types. These entity types don't have shadow properties, and ...
Read more >
How to query a property bag entity type in EFCore5?
You can index the dictionary directly, with knowledge of the column name. Working example would be: joinTable.Where(d => d[columnName] ...
Read more >
What's New in EF Core 5.0
Shared-type entity types and property bags. EF Core 5.0 allows the same CLR type to be mapped to multiple different entity types; ...
Read more >
Microsoft Releases Entity Framework Core 5.0 RC 1
Property -bag entity types are also part of the many-to-many ... can be used as an entity type - and ultimately as a...
Read more >
Oleg Kyrylchuk
EF Core 5.0 introduces shared-type entities and property bags. The share-type entity allows the same CLR type to be mapped to multiple ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found