Make it easier to use semantic datatypes with EF core.
See original GitHub issueA semantic data type is a struct or class with a single member of a primitive type. For example:
struct Email
{
public string Value {get; set;}
// other code, but no other public properties or fields
}
I use semantic data types to prevent stupid programming errors like assigning an email address to a user code or assigning a employeeId to a studentId. I get the errors at compile time.
EmployeeId employeeId = 3;
StudentId studentId = employeeId ; // gives compiler error
int employeeId = 3;
int studentId = employeeId ; // compiles but give an error at run-time or causes unexpected behavior.
However for each data type I have to make a bit of plumbing code to make it work with EF core and with Json.
I want to get rid of or the plumbing code perhaps using an extra data annotation or extra function in the context:
[UseSingleValue]
struct Email
{
public string Value {get; set;}
}
or (but not preferred by me)
entity.Property(e => e.Email).UseSingleValue<Email>(v => v.Value)
So EF core knows that a property of type Email really is a string stored in property Value and generates the plumbing code it self.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
EF Core - How to Configure Column Type depending on ...
I want to configure the column types depending on the database provider used. For example: public class MyClass { public Guid Id {...
Read more >Part 5, Razor Pages with EF Core in ASP.NET Core - Data ...
The Contoso University web app demonstrates how to create Razor Pages web apps using EF Core and Visual Studio. For information about the ......
Read more >Entity Framework Core: User-defined Fields and Tables
Using dynamically created fields or even entities in raw SQL shouldn't be a problem, but it gets more challenging when working with Entity...
Read more >Data types and semantic types | Community Connectors
In addition to data types, Looker Studio also makes use of semantic types. Semantic types help to describe the kind of information the...
Read more >Sato: Contextual Semantic Type Detection in Tables
Sato achieves this high prediction accuracy using a novel hybrid model that regulates semantic type pre- diction using signals from the global context...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You could visit every property in your
OnModelCreating
, egmodelBuilder.Model.GetEntityTypes().Select(t => t.GetProperties())
and create a converter based on reflection information.Seems like the rest of this is about value objects, so we can probably close as a dup of #9906.