Hi
I am trying to implement Owned Types in a particular DbContext (which I can get to work ok using Sql Server). However, it seems like there are mapping issues with the hidden/shadow property that's get automatically created by the EF Core 2 classes
My entity is defined with a primary key whose property name is Id which is defined as a long in the .net class. This has a column type of NUMBER in the Oracle Database.
builder.HasKey(x => x.Id);
builder.Property<long>(x => x.Id).HasColumnName(@"DISPENSE_ID").HasColumnType(@"NUMBER").IsRequired().ValueGeneratedNever();
When I try to use an owned type to 'contain a group of similarly related properties' within my main entity
builder.OwnsOne(p => p.DispenseTotals).Property<System.Nullable<decimal>>(x => x.NetAmount).HasColumnName(@"NET_AMOUNT").HasColumnType(@"NUMBER").ValueGeneratedNever();
public class DispenseTotals
{
public virtual System.Nullable<decimal> NetAmount
{
get;
private set;
}
}
I obtain the following error when trying to load the entity from the database:
'Dispense.Id' and 'Dispense.DispenseTotals#DispenseTotals.DispenseId' are both mapped to column 'DISPENSE_ID' in 'DISPENSE' but are configured to use different data types ('NUMBER' and 'int64').
My main entity is called Dispense which contains a property DispenseTotals, as far as I know I should not have to add a DispenseId to the DispenseTotals class (and doing so results in another error Devart.Data.Oracle.OracleException: 'ORA-00918: column ambiguously defined)
I cannot seem to resolve this auto mapping error. Is there any way to explicitly force the hidden / auto generated field
'Dispense.DispenseTotals#DispenseTotals.DispenseId' to be converted correctly.
This works out of the box in SQL Server (but no mapping is required).
Table splitting works correctly for me in Oracle and Sql Server, but in a number of cases I am looking to use the Owned Type approach to group related properties in a particular entity.
Regards Simon
Owned types are discussed in the following Microsoft article / issue:
https://github.com/aspnet/EntityFramewo ... issues/466
EF CORE 2 AND OWNED TYPES
Re: EF CORE 2 AND OWNED TYPES
Thank you for your report. We will investigate the question and notify you about the result.
JIC: we removed your duplicated message in the thread viewtopic.php?t=36091
JIC: we removed your duplicated message in the thread viewtopic.php?t=36091
Re: EF CORE 2 AND OWNED TYPES
The bug with explicit specifying .HasColumnType for PK property, when the entity has Owned Type, in EF Core 2 is fixed.
As a workaround with a current public build, please remove .HasColumnType(@"NUMBER") from your mapping of the Id property.
As a workaround with a current public build, please remove .HasColumnType(@"NUMBER") from your mapping of the Id property.
Re: EF CORE 2 AND OWNED TYPES
New build of dotConnect for Oracle 9.5.454 is available for download now: viewtopic.php?f=1&t=36602.
-
- Posts: 3
- Joined: Thu 19 Oct 2017 17:31
Re: EF CORE 2 AND OWNED TYPES
Hi I still obtain issues when attempting to use owned types.
I am using 9.5.454 of both Devart.Data.Oracle and Devart.Data.Oracle.EFCore along with Microsoft.EntityFrameworkCore 2.01
I no longer have to specify the .HasColumnType(@"NUMBER") for a pk file (this now seems to automatically translate to the long c# data type)
However, when I attempt to use Owned types in the IEntityTypeConfiguration builder class :
builder.OwnsOne(p => p.DispenseTotals).Property<System.Nullable<decimal>>(x => x.NetAmount).HasColumnName(@"NET_AMOUNT").HasColumnType(@"NUMBER").ValueGeneratedNever();
I receive issues that oracle cannot identify the columns in the owned type I am using. So in the example above it appears like the mapping to the DispenseTotals property is not being registered correctly.
Regards Simon
I am using 9.5.454 of both Devart.Data.Oracle and Devart.Data.Oracle.EFCore along with Microsoft.EntityFrameworkCore 2.01
I no longer have to specify the .HasColumnType(@"NUMBER") for a pk file (this now seems to automatically translate to the long c# data type)
However, when I attempt to use Owned types in the IEntityTypeConfiguration builder class :
builder.OwnsOne(p => p.DispenseTotals).Property<System.Nullable<decimal>>(x => x.NetAmount).HasColumnName(@"NET_AMOUNT").HasColumnType(@"NUMBER").ValueGeneratedNever();
I receive issues that oracle cannot identify the columns in the owned type I am using. So in the example above it appears like the mapping to the DispenseTotals property is not being registered correctly.
Regards Simon
Re: EF CORE 2 AND OWNED TYPES
1. Please specify the exact text of the error and its full stack trace.
2. Could you modify this test project for reproducing and upload it to ftp://ftp.devart.com (credentials: anonymous / yourEmail).
2. Could you modify this test project for reproducing and upload it to ftp://ftp.devart.com (credentials: anonymous / yourEmail).