Page 1 of 1
Complex Type column mapping - force upper case column?
Posted: Tue 19 Aug 2014 19:53
by rmagruder
Entity Framework Code First -> Oracle
I have a complex type called DateRange and it has a StartDate and StopDate in it.
In my entity, I have a property called RedemptionDateRange of this type.
A column generated is RedemptionDateRange_StartDate. This is all well and good except it needs to be upper case. If I try to override the Column() attribute with Data Annotations, it doesn't do the combining of PropertyName_ComplexPropertyName anymore. I need to make sure I can still re-use DateRange elsewhere in the same entity, but it looks like all or nothing.
is there any way I can tell DevArt and/or EF to uppercase the column names? It's a DBA-requirement I'm afraid (eyeroll).
Re: Complex Type column mapping - force upper case column?
Posted: Thu 21 Aug 2014 08:13
by MariiaI
This is all well and good except it needs to be upper case.
To make table names, column names be in upper case in Oracle, you should create tables without quoting. You can avoid quotes in runtime using the Workarounds class, specifically the DisableQuoting property:
Code: Select all
var config = OracleEntityProviderConfig.Instance;
config.Workarounds.DisableQuoting = true;
You can also do it in the config file of your application:
Code: Select all
<configSections>
<section name="Devart.Data.Oracle.Entity" type="Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfigurationSection,
Devart.Data.Oracle.Entity, Version=8.4.225.6, Culture=neutral, PublicKeyToken=09af7300eec23701" />
</configSections>
<Devart.Data.Oracle.Entity xmlns="http://devart.com/schemas/Devart.Data.Oracle.Entity/1.0">
<Workarounds DisableQuoting="true" />
</Devart.Data.Oracle.Entity>
</configuration>
You can find some information about this and other workarounds here:
http://blog.devart.com/new-features-of- ... orkarounds
I need to make sure I can still re-use DateRange elsewhere in the same entity, but it looks like all or nothing.
You can try using fluent mapping approach in this case. For example:
Code: Select all
modelBuilder.Entity<ClassT>()
.HasKey(p => new { p.id })
.ToTable("ClassTs");
// Properties:
modelBuilder.Entity<ClassT>()
.Property(p => p.id)
.IsRequired()
.HasColumnType("int");
modelBuilder.Entity<ClassT>()
.Property(p => p.RedemptionDateRange.StartDate)
.HasColumnName(@"RedemptionDateRange_StartDate")
.HasColumnType("timestamp");
modelBuilder.Entity<ClassT>()
.Property(p => p.RedemptionDateRange.StopDate)
.HasColumnName(@"RedemptionDateRange_StopDate")
.HasColumnType("timestamp");
modelBuilder.Entity<ClassT>()
.Property(p => p.Property1.StartDate)
.HasColumnName(@"Property1_StartDate")
.HasColumnType("timestamp");
modelBuilder.Entity<ClassT>()
.Property(p => p.Property1.StopDate)
.HasColumnName(@"Property1_StopDate")
.HasColumnType("timestamp");
If it is not what you mean or you have any further questions, feel free to contact us.
Re: Complex Type column mapping - force upper case column?
Posted: Thu 21 Aug 2014 16:24
by rmagruder
Thanks!
I had found the workaround you mentioned but hadn't tried it yet because I was a little concerned that it might break something else.
As to the block fluent C#, I had been wondering if there was a way to do it with Data Annotations, but that doesn't seem as powerful as using the Fluent API.
Between the two suggestions you gave, do you have a preference? (Fluent direct fixing of field names vs. dumping all quotes?)
Thanks,
Randy
Re: Complex Type column mapping - force upper case column?
Posted: Thu 21 Aug 2014 17:39
by rmagruder
One other area impacted by this. When using a TPH inheritance type with Code First, a field is created: Discriminator.
Any way to make that DISCRIMINATOR? Or does this push me firmly in the 'no quotes' solution camp?
Re: Complex Type column mapping - force upper case column?
Posted: Fri 22 Aug 2014 12:19
by MariiaI
Between the two suggestions you gave, do you have a preference? (Fluent direct fixing of field names vs. dumping all quotes?)
You can use them simultaneously. Fluent mapping approach will be very useful if you want to use one complex type (e.g., DateRange) in one entity class more then once.
Any way to make that DISCRIMINATOR? Or does this push me firmly in the 'no quotes' solution camp?
Both proposed solutions can be used, i.e. DisableQuoting and Fluent mapping:
Code: Select all
modelBuilder.Entity<Test1>()
.HasKey(p => new { p.id })
.Map(tph => {
tph.Requires("Test_DISCRIMINATOR").HasValue("1");
tph.ToTable("Test1s");
});
Re: Complex Type column mapping - force upper case column?
Posted: Fri 22 Aug 2014 13:28
by rmagruder
Gotcha! I love Data Annotations, but boy does it seem like Fluent has all the power!