-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possibile to customize the default mappings in Oracle.EntityFrameworkCore for Scaffold-DbContext ? #157
Comments
Oops sorry I put a wrong link to documentation, the right one is here. This documentation contains an advice should you wish to change manually the default mapping in the file, e.g. "When scaffolding, developers may wish to change the default data type mappings between Oracle Database and .NET. When modifying .NET CLR types of the generated entity's property, remove the auto-generated HasColumnType() Fluent API in the model." The problem with this solution is that if I change manually the auto-generated files, all the changes will be overwritten whenever a new Scaffold-DbContext operation is done (for example after an update to the tables structure). Is it possible somehow to define a custom default mapping to be used by Scaffold-DbContext ? |
Not at this time. I filed Bug/ER 32633191 to track this request with my Oracle team. As a workaround, when the underlying table changes, you can modify the mapping manually rather than using Scaffold-DbContext. Alternatively, you can generate a new mapping with Scaffold-DbContext, then apply only the changes to the existing mapping for the DB schema changes added. Are these capable workarounds for your use case? |
Yes, I can manage meanwhile with the second option. What I mainly wanted was to point out this limitation and to get it addressed in future releases. Thank you for the prompt reply. |
A requirement came to my mind which you may take into consideration: besides allowing the mapping of a general Oracle datatype (e.g. NUMBER(3)) to .NET type (e.g. short) the configuration file should also allow the mapping of a Oracle datatype of a particular field of a table to .NET type. This is useful to manage particular exceptions, for example usually NUMBER(3) is mapped to byte (unsigned), but for the field x of table y it should be mapped to sbyte (signed). |
Just ran into this same issue after our project upgraded from .Net Core 3.1 to 6.0.
Was a solution ever found? |
We have the same Problem as @loftusjl |
@loftusjl @GrimmT Are you looking for an warning suppression solution or to have a different default mapping during the scaffolding process? The Oracle dev team is working on changing the default data type mappings for scaffolding to provide a more natural alignment between corresponding Oracle DB and .NET data types. We think that would address many of the customer concerns around managing Oracle EF Core scaffolding data type mapping. |
Hi @alexkeh I am not sure if this issue here is really the right one for our problem. (I posted it here since @loftusjl seems to have the same problem)
When we run our asp.net core web server on .NET Core 3.1 and Oracle.EntityFrameworkCore Version=3.19.80 there are no warnings in our loggs.
I think the corresponding ef core breaking change is the following one: https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-5.0/breaking-changes#decimals
|
@GrimmT We ended up having to change the precision of the suspect columns based on the Data Type Mapping table found in the Scaffolding Or Reverse Engineering section of the Oracle documentation. Similarly, we ran into an issue a bit later where the database had been developed with NUMBER(1) which was defaulting to boolean when we required integers. We had to increase the precision to 5 within the database for them to scaffold correctly.
@alexkeh My team was looking for different mapping in the scaffolding process. Looking forward to the scaffolding changes. |
@GrimmT If you are verifying the data sizes fit within the target data types you are saving to already, this warning message shouldn't be a problem. I don't enough about how this validation works for why you are still seeing a warning. .NET provides a few ways you can suppress specific warnings. |
We verified, that the smallest and biggest data points we can have in our system, are correctly be read and written to and from the database. |
Just to add another scenario. The Oracle system I'm currently working on, has primary keys of NUMBER(10) and foreign keys of NUMBER(19). This is currently worked around because it's .NET framework (4.5.1 !) and using the in app.config. At the moment, I'm unable to get the DBA to agree to synchronise the types. Trying to use Scaffold-DbContext generates the error. |
I'm sorry but these default type mappings are incredibly awful for the simple reason that if I'm scaffolding a DbContext from an existing database, I expect to be able to read the existing data. There's an argument to be made for mapping all NUMBER columns with s != 0 to System.Decimal on the basis that it's unlikely the column will actually contain a number which will not fit in a System.Decimal; however to map NUMBER(1) to System.Boolean and any NUMBER value to System.Byte (an unsigned value) is just wrong. The insertion-safety rationale isn't even consistently applied! NUMBER(4) maps to System.Byte so I can't exceed the column size, but NUMBER(11) (correctly) maps to System.Int64 which has a maximum value of 9,223,372,036,854,775,807? If I try and insert that, I rightly earn the ensuing DoingItWrongException and can fix my code or the column. |
I read the documentation of Oracle.EntityFrameworkCore, yet it does not contain any information about how to customize the default mappings. Is is possible somehow ? .NET version allowed the customization through app.config, what about .NET CORE ?
The text was updated successfully, but these errors were encountered: