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

Flat Inheritance with One-to-Many association

1 Answer 26 Views
Design Time (Visual Designer & Tools)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andy
Top achievements
Rank 1
Andy asked on 17 Apr 2014, 06:08 PM
I am having problems creating a model that uses Flat inheritance of a base type to multiple other classes.  Basically I have a base type of “Addresses”,  I also have other entity types, Corporations, Customers, Locations, Providers……  I want to store all of the address for those entities in the Addresses table. Each one of the entities may have multiple different addresses.  I have established child classes of Addresses with the discriminator column set (ex, CorpAddresses, CustomerAddresses) and established an association between the entities and the respected type and set managed to true.  All of the associations are set to use the same “Parent_ID”, and I have a feeling that is the problem. 

 

When I try to insert any address besides whatever association I set up first,  I get Foreign Key constraint exceptions.  Is there another way that I can get around this or I going to be stuck using multiple back end address tables.  I was wanting to keep them all in one table if possible to make querying for addresses and spatial mapping entities a little easier
.   

Thanks for the help in advance.  

1 Answer, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 22 Apr 2014, 06:19 PM
Hi Andy,

If I correctly understand your scenario, you have one-to-many association where on the source side you have the Addresses class which is a base class and in the target side you want to have a navigation collection property from this base type. Unfortunately you cannot create a navigation collection from the base type and use it as you can use a polymorphic references, this is not supported by Telerik Data Access.

Still for Flat Inheritance there is a workaround which you can use, but you can use it only to get the related addresses from the database and you will not be able to add a new address in the navigation collection. Let's assume that you have an association between two tables - Addresses and Customers and in the Addresses table there is a Foreign Key column CustomerId. For Flat Inheritance you can get all entities with the context.GetAll<T>() method. So in your case you can create an extension method in the EntitiesModel class, which returns all addresses related to one Customer:
public partial class EntitiesModel
{
    public IEnumerable<Addresses> GetAddresses(Customer customer)
    {
        this.GetAll<Addresses>().Where(adr => adr.CustomerId == customer.Id);
    }
}

I hope that helps. If any other questions arise or you want to achieve something different, 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.
 
Tags
Design Time (Visual Designer & Tools)
Asked by
Andy
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Share this question
or