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).
Complex Type column mapping - force upper case column?
Re: Complex Type column mapping - force upper case column?
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:This is all well and good except it needs to be upper case.
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>
http://blog.devart.com/new-features-of- ... orkarounds
You can try using fluent mapping approach in this case. For example:I need to make sure I can still re-use DateRange elsewhere in the same entity, but it looks like all or nothing.
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");
Re: Complex Type column mapping - force upper case column?
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
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?
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?
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?
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.Between the two suggestions you gave, do you have a preference? (Fluent direct fixing of field names vs. dumping all quotes?)
Both proposed solutions can be used, i.e. DisableQuoting and Fluent mapping:Any way to make that DISCRIMINATOR? Or does this push me firmly in the 'no quotes' solution camp?
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?
Gotcha! I love Data Annotations, but boy does it seem like Fluent has all the power!