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

Fluent Model Associations Error with Horizontal Inheritance

4 Answers 47 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul
Top achievements
Rank 1
Paul asked on 18 Aug 2014, 10:40 PM
Hi,

My team is working with Open Access 2013.2.702.1 to build an ORM mapping against a legacy database.  I have defined some classes with Horizontal inheritance, but I can't seem to add an association to the base class.  I have gone over the forums looking for similar problems, and have based my approach on the discussion originally had in this thread, but I'm now getting an error that I can find no help for.  I'd appreciate any insight anyone can offer.

The exception is:
Not implemented: Columns expressions is null, is this horizontal? (1)
   at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQueryImpl(Type resultType, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid)
   at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid)

I have created a minimal example that replicates the problem consistently.  Here are my entities:
public class Address
{
    public int Id { get; set; }
    public string AddressLine1 { get; set; }
    public string City { get; set; }
    public string Province { get; set; }
    public string Country { get; set; }
    public string PostalCode { get; set; }
 
    // Foreign Keys
    public int EntityId { get; set; }
}
public class Entity
{
    private IList<Address> addresses = new List<Address>();
 
    public int Id { get; set; }
 
    public IList<Address> Addresses
    {
        get { return addresses; }
        set { addresses = value; }
    }
}
public class Individual : Entity
{
    public string NameFirst { get; set; }
    public string NameLast { get; set; }
}
public class Organization : Entity
{
    public string Name { get; set; }
}

Here is my mapping, which is based on information from the thread I mentioned before (specifically, fully-qualifying the backing fields).  I have experimented with explicitly providing all of the properties as expressions in the MapType() argument, but the same exception was still raised, so I left it out of this snippet to save space.
protected override IList<MappingConfiguration> PrepareMapping()
{
    List<MappingConfiguration> configurations = new List<MappingConfiguration>();
 
    var address = new MappingConfiguration<Address>();
    address.MapType().ToTable("Addresses");
    address.HasProperty(a => a.Id).IsIdentity(KeyGenerator.Autoinc);
    configurations.Add(address);
 
    var entity = new MappingConfiguration<Entity>();
    entity.MapType().Inheritance(InheritanceStrategy.Horizontal);
    configurations.Add(entity);
 
    var individual = new MappingConfiguration<Individual>();
    individual.MapType().ToTable("Individuals");
    individual.HasProperty(i => i.Id).IsIdentity(KeyGenerator.Autoinc);
    individual.HasAssociation(i => i.Addresses).HasFieldName("Entity.addresses").ToColumn("EntityId");
    configurations.Add(individual);
 
    var organization = new MappingConfiguration<Organization>();
    organization.MapType().ToTable("Organizations");
    organization.HasProperty(o => o.Id).IsIdentity(KeyGenerator.Autoinc);
    organization.HasAssociation(o => o.Addresses).HasFieldName("Entity.addresses").ToColumn("EntityId");
    configurations.Add(organization);
     
    return configurations;
}

Thanks in advance.

4 Answers, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 21 Aug 2014, 06:01 PM
Hello Paul,

As I saw in the second code snippet which you sent, there is missing the definition of the mapping for Id column in the parent class. It should look:
var entity = new MappingConfiguration<Entity>();
entity.MapType().Inheritance(InheritanceStrategy.Horizontal);
entity.HasProperty(p => p.Id).IsIdentity();
configurations.Add(entity);
After this the association should be defined. Unfortunately I have tested this with the latest version of Telerik Data Access.

I hope that helps.

Regards,
Boris Georgiev
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
Paul
Top achievements
Rank 1
answered on 21 Aug 2014, 07:50 PM
Hi Boris,

Thanks for your suggestion.  I have tried adding the AutoInc Identity specification to the Id column of the base class, and the error message continues to appear.

To clarify further, the error only occurs when I try to query a collection of Entity objects - querying Organizations or Individuals directly does not cause the error.

That is, this works:
var result = context.GetAll<Individual>().ToList();

This does not:
var result = context.GetAll<Entity>().ToList();

I would expect the result of this query to be a union of Organizations and Individuals which I could query based on their shared properties (Addresses, in this case, but ideally others going forward).  Am I making an incorrect assumption?
0
Accepted
Boris Georgiev
Telerik team
answered on 26 Aug 2014, 12:17 PM
Hi Paul,

Please excuse me for the misunderstanding.

Unfortunately you have bumped against a limitation in Telerik Data Access. It is not possible to select all entities in the horizontal inheritance by selecting GetAll for the base class.

If you have any further questions, do not hesitate to contact us again.

Regards,
Boris Georgiev
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
Paul
Top achievements
Rank 1
answered on 26 Aug 2014, 02:18 PM
While it is not the answer I hoped for, it is what I needed to verify.

Thanks, Boris.
Tags
General Discussions
Asked by
Paul
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Paul
Top achievements
Rank 1
Share this question
or