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

Splitting a table into to entites

1 Answer 43 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.
Nikesh
Top achievements
Rank 1
Nikesh asked on 25 Sep 2012, 04:53 PM
Hi All

I currently have a db table called country which contains the following fields:

* CountryCode
* ISOCode
* Region
* CurrencyCode
* Unit

I haven then created a view on top of this table and created a model using database first approach using the view. Instead of creating a single entity called Country I want the model to create the following two entities:

public partial class Country
{
    private string _countryCode;
    public virtual string CountryCode
    {
       get { return this._countryCode;}
       set {this._countryCode = value;}
    }
         
    private string _iSOCode;
    public virtual string ISOCode
    {
        get {return this._iSOCode;}
        set { this._iSOCode = value;}
    }
         
    private string _region;
    public virtual string Region
    {
        get{return this._region; }
        set{this._region = value;}
    }
}
 
public partial class Ccy
{
    private string _unit;
    public virtual string Unit
    {
        get{return this._unit;}
        set{this._unit = value;}
    }
         
    private string _currencyCode;
    public virtual string CurrencyCode
    {
        get{return this._currencyCode;}
        set{this._currencyCode = value;}
    }
}


I tried manually creating two entities which map to the same table but got an error that two entities can not map to the same view. Can someone point me in the right direction on how to do this in OpenAccess?

1 Answer, 1 is accepted

Sort by
0
Doroteya
Telerik team
answered on 27 Sep 2012, 04:11 PM
Hi Nikesh,

In general, OpenAccess ORM allows you to map more than one class to a single table if the structure of the classes is hierarchical. In other words: if you have the Animal class and the Dog class, you can map them to the same table, if the Dog class inherits the Animal class. 

OpenAccess offers different ways to model inheritance hierarchies in a relational database (additional general information):
    - vertical inheritance mapping - each class has its own table containing only its fields (video).
    - horizontal inheritance mapping - instead of, the topmost class in a hierarchy to have a table of its own, each immediate subclass is stored in a table with a "copy" of the fields from the superclass (video).
    - flat inheritance mapping - fields from the subclasses are mapped to a superclass table (video).
    - complex inheritance mapping - mixing vertical and flat inheritance (video).

From the code you posted and since you mention that you use the database first approach, my best guess is that you are trying to implement flat inheritance mapping. If that is the case, in addition to the video you can check here for a step-by-step guide.

However, if I my assumption is wrong or if you experience any difficulties in the implementation of the inheritance hierarchies in your model, do not hesitate to get back to us.


All the best,
Doroteya
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Tags
Data Access Free Edition
Asked by
Nikesh
Top achievements
Rank 1
Answers by
Doroteya
Telerik team
Share this question
or