EF CORE 2 AND OWNED TYPES
Posted: Tue 09 Jan 2018 17:09
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
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