This is a migrated thread and some comments may be shown as answers.

Using associations in combination with horizontal inheritance

2 Answers 39 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Catalin
Top achievements
Rank 1
Catalin asked on 16 Jul 2015, 09:18 AM

Hi Telerik team,

i have a problem modelling a combination of association with horizontal inheritance.

My sample code is this:

public class Parent
{
  public int Id { get; set; }
  public string Title { get; set; }
  public IList<ExecChild> ExecChildren { get; set; }
}
 
public abstract class ExecChild
{
  public String Title { get; set; }
  public Parent Parent { get; set; }
}
 
public class Executor : ExecChild
{
  public int Id { get; set; }
  public int Number { get; set; }
}
 
public class MappingH
{
  public static IEnumerable<MappingConfiguration> Configurations
  {
    get
    {
      var parent = new MappingConfiguration<Parent>();
      parent.HasProperty(p => p.Id).IsIdentity(KeyGenerator.Autoinc);
      parent.HasAssociation(p => p.ExecChildren).WithOpposite(c => c.Parent);
      parent.MapType().ToTable("Parent");
      yield return parent;
 
      var execChild = new MappingConfiguration<ExecChild>();
      execChild.MapType().Inheritance(InheritanceStrategy.Horizontal);
      yield return execChild;
 
      var executor = new MappingConfiguration<Executor>();
      executor.HasProperty(d => d.Id).IsIdentity(KeyGenerator.Autoinc);
      executor.MapType(t => new
      {
        Id = t.Id,
        Number = t.Number
      }).ToTable("Executor");
      yield return executor;
    }
  }
}

The code compiles without any problem, but at the run-time at the line creating the DDL script:

script = schemaHandler.CreateUpdateDDLScript(null);

at get this exception:

An unhandled exception of type 'Telerik.OpenAccess.Exceptions.MetadataException' occurred in Telerik.OpenAccess.dll
Additional information: Failed to create main table indexes of class 'ExecChild'.​

 

Can you help me with this problem?

How to map this kind of structure to a DB using horizontal inheritance?

Thanks!

 

 

 

2 Answers, 1 is accepted

Sort by
0
Catalin
Top achievements
Rank 1
answered on 17 Jul 2015, 02:28 PM

Not need to replay, I found the answer here:

http://www.telerik.com/support/kb/data-access/details/forward-mapping-models-for-classes-in-an-inheritance-hierarchy

 

0
Ady
Telerik team
answered on 21 Jul 2015, 10:13 AM
Hi Catalin,

 Glad you found the reply.
Do get back in case you need further assistance.

Regards,
Ady
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
Data Access Free Edition
Asked by
Catalin
Top achievements
Rank 1
Answers by
Catalin
Top achievements
Rank 1
Ady
Telerik team
Share this question
or