EF CORE 2 AND OWNED TYPES

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
simonbeaumont909
Posts: 3
Joined: Thu 19 Oct 2017 17:31

EF CORE 2 AND OWNED TYPES

Post by simonbeaumont909 » 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

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EF CORE 2 AND OWNED TYPES

Post by Shalex » Fri 12 Jan 2018 17:12

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

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EF CORE 2 AND OWNED TYPES

Post by Shalex » Thu 08 Feb 2018 13:26

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.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EF CORE 2 AND OWNED TYPES

Post by Shalex » Thu 15 Feb 2018 17:59

New build of dotConnect for Oracle 9.5.454 is available for download now: viewtopic.php?f=1&t=36602.

simonbeaumont909
Posts: 3
Joined: Thu 19 Oct 2017 17:31

Re: EF CORE 2 AND OWNED TYPES

Post by simonbeaumont909 » Mon 12 Mar 2018 10:37

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

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EF CORE 2 AND OWNED TYPES

Post by Shalex » Mon 19 Mar 2018 15:18

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).

Post Reply