Inheritance Issue with Oracle XE
Posted: Thu 06 Dec 2012 18:39
I'm having an inheritance issue that only seems to happen in Oracle XE. I've tried this in both 7.2.104 and 7.3.132 versions. Here's my setup:
In Oracle Standard, this code correctly prints out "Child is a Child". However, in Oracle XE this code prints out "Child is a SubChild". Is this a known issue? Using the DBMonitor I verified that the SQL that gets executed against the database is the exact same in Standard and XE.
Thanks,
Nathan
Code: Select all
public class Parent
{
public int Id { get; set; }
public virtual Child Child { get; set; }
public int ChildId { get; set; }
}
public class Child
{
public int Id { get; set; }
}
public class SubChild : Child
{}
public class TestDbContext : DbContext
{
public IDbSet<Parent> Parents
{
get { return Set<Parent>(); }
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<ColumnTypeCasingConvention>();
modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
var parentConfig = modelBuilder.Entity<Parent>();
parentConfig.HasKey(p => p.Id);
parentConfig.HasRequired(p => p.Child)
.WithMany()
.HasForeignKey(p => p.ChildId);
parentConfig.Property(p => p.ChildId)
.HasColumnName("ChildId");
modelBuilder.Entity<Child>()
.HasKey(c => c.Id);
var subChildConfig = modelBuilder.Entity<SubChild>();
subChildConfig.HasKey(s => s.Id);
subChildConfig.ToTable("SubChildren");
}
}
class Program
{
private static void Main(string[] args)
{
new Devart.Data.Oracle.OracleMonitor {IsActive = true};
int parentId;
using (var context = new TestDbContext())
{
var parent = new Parent
{
Child = new Child()
};
context.Parents.Add(parent);
context.SaveChanges();
parentId = parent.Id;
}
using (var context = new TestDbContext())
{
var parent = context.Parents
.Include(p => p.Child)
.Single(p => p.Id == parentId);
Console.WriteLine("Child is a " + parent.Child.GetType());
Console.ReadKey();
}
}
}
Thanks,
Nathan