The goal of this issue is to track and rationalize various levels or flavors of "dynamic behavior" we could attain with EF in the future.
The initial list is based on digesting information provided in various bugs such as #1513 and #2141 as well as conversations with various teams and previous research on feature gaps with other persistence frameworks.
Note that none of this is planned for EF Core 1.0.0 and before we start bringing dynamic features into EF we should probably open more issues and prioritize each individual feature independently. But at least for now should any new "dynamic" scenario be brought to our attention by the community or should our understanding of them improve we can just keep this list up to date:
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.Moving this straight to the backlog.
Hello, just a thought on this, instead of DB first there could be a JSON or even XML first equivalent.
This would help with materializing Annotatable objects. Currently we can get close by using shadow properties and then doing a post-materialization fixup.
c#
var post = context.Posts.First();
var entry = context.Entry(post);
var isDraft = entry.Property("IsDraft").CurrentValue as bool;
post.AddAnnotation("IsDraft", isDraft);
Of course this has caveats: AFAIK the only way to get a shadow property value after materialization is to use change tracking. This means to AsNoTracking() cannot be used if the shadow property is required outside of query.
Are there plans to make a progress on this feature request?
This will enable implementation of F# erased type providers for EF Core.
Triage: Consider scenario described here when tackling this issue: #10555
Dynamic functionality is very essential in almost any growing app, especially LoB apps or apps that grow quickly and dynamically.
Let me just demonstrate with a couple of examples using a Contact class.
c#
var number = CleanNumber(number); //remove formatting
dbContext.Contacts
.Where(c =>
c.Phones.Where(p => p.Label = "Work" && p.Number.Contains(number));
Contact entity at all, instead I need them to be all dynamic, for example, I'd sometimes want Contact to have a person name, whereas sometimes a company name, in many other scenarios the user would want to add custom fields.Let's take Microsoft SQL Server as our DB provider. It provides out the box support for that using JSON/XML
datatype. We could transform all the data fields that we defined as dynamic to be stored and manipulated as JSON/XML.
@weitzhandler - I was reading this thread. While dynamic entity types has a wide scope, I believe the scenario you posted could possibly work in current system already.
Tuple/list may be slightly difficult, but if you are using Dictionary/Array and using JSON on server side to store, you could value converter to store your data. And for querying part use DbFunction to access data on server and get queries translated. It also covers when you don't have LabelNames defined and you want to use dynamic "key".
In the future, this (especially the queryability) has to be implemented in the system with no need for DbFunctions.
We will have to distinguish between 'converted' fields and 'dynamic' fields. The difference is that converted fields is uncontrolled, and queryability is not expected from it in the first place. Whereas 'dynamic' fields, are such that the EF is aware of them being dynamic, hence takes care of its conversion/transformation/serialization (JSON/XML etc.), and have the internal query providers generate a different query if the columns in question are of JSON/XML.
@weitzhandler - Of course, functions related to JSON support on query side would be implemented in #4021 XML could achieve the similar. This also have some overlap with property bag entities. Regardless, most of work here would be about changing the metadata for representation. Query side comes into picture depending on how it is stored on server & what we can translate.
Most helpful comment
Hello, just a thought on this, instead of DB first there could be a JSON or even XML first equivalent.