Splitting a table into to entites

Thread is closed for posting
2 posts, 0 answers
  1. Nikesh
    Nikesh avatar
    12 posts
    Member since:
    Nov 2011

    Posted 25 Sep 2012 Link to this post

    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?
  2. Doroteya
    Doroteya avatar
    498 posts

    Posted 27 Sep 2012 Link to this post

    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,
    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!
Back to Top