A tabel and a view that extends it: how to make them working together

Thread is closed for posting
3 posts, 0 answers
  1. tmlipinski
    tmlipinski avatar
    131 posts
    Member since:
    Dec 2006

    Posted 10 Mar 2009 Link to this post

    Hi,

    There is a table Tb. And there is a view Vw that just extends data from Tb (shows all columns from Tb plus some more). I can create an independent persistent class form this view (manually :-(; there is no support for reverse mapping of views...) and it works. But because they are independent classes, each time I modify the structure of Tb I must modify both classes; for the same reason I cannot cast Vw class to Tb class; and so on.
    I would like to have Vw class inheriting from Tb:
    class Vw: Tb
    but I don't know how to set their configuration in app.config.
    For example, let it be:
    Table Tb, columns: id, A, B (all ints)
    View Vw, columns: id, A, B (directly from Tb), C (from somewhere) - all ints
    Classes:
    [Telerik.OpenAccess.Persistent()]  
    public class Tb  
    {  
      private int id;    
      private int a;    
      private int b;    
      public Tb()   
      {}  
          
      [Telerik.OpenAccess.FieldAlias("id")]  
      public int Id  
      {  
        get { return id; }  
        set { this.id = value; }  
      }  
          
      [Telerik.OpenAccess.FieldAlias("a")]  
      public int A  
      {  
        get { return a; }  
        set { this.a = value; }  
      }  
          
      [Telerik.OpenAccess.FieldAlias("b")]  
      public int B  
      {  
        get { return b; }  
        set { this.b = value; }  
      }  
    }  
     
    public class Vw : Tb  
    {  
      private int c;  
     
      public Vw()  
        : Tb()  
      { }  
          
      [Telerik.OpenAccess.FieldAlias("c")]  
      public int C  
      {  
        get { return c; }  
        set { this.c = value; }  
      }  
    How would the appropriate app.config fragment look like?

    And the other question is: is it possible to create such a configuration and make code generator to create both classes (reverse mapping but not: DB -> config -> C# code but only: config -> C# code)

    Regards
    Tomasz
  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 13 Mar 2009 Link to this post

    Hello tmlipinski,
    you do not need to set it manually. The OpenAccess Forward mapping tool will do it for you. You can review this KB for more information regarding the inheritance.
    Regarding your second question: Yes this is a possible scenario. You can write your classes in the reversemapping.config file and use the reverse mapping tool to convert them to c# code and mapping.

    Kind regards,
    PetarP
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. tmlipinski
    tmlipinski avatar
    131 posts
    Member since:
    Dec 2006

    Posted 13 Mar 2009 Link to this post

    Hi,
    This KB article describes the vertical hierarchy, with two tables. When reading data of employees (in this KB) we must ask both tables. In my case we have a table and a view. Reading data of Vw objects we must read the view only. I'm not sure if we can express this case in ORM terms at all. There is no - and can't be - any voa_class column in Tb nor in Vw.
    In the real life, it's a case of two tables designed for customization and localization of an application (the description below is simplified):
    - the first one, that is Tb in my imaginery example, contains names of texts (e.g. "btnStop", "btnClose" etc.) and their codes - some kind of a link to the second table
    - the second one, let's name it LocTxt, contains localized texts and consists of three columns:
    • code (integer)
    • language code ("en-US", "fr" etc.)
    • text

    "code" is the same for all language versions of the same text ({1, "en", "Stop"}, {1, "fr", "Arret}). The pair: code - language code is the primary key in this table. and the first table, Tb, contains "code" only.
    What makes the case more difficult is that Tb is not the only table that uses LocTxt. For example there is a table with dictionary items (of various dictionaries) that keeps texts of their items in LocTxt. Therefore Tb doesn't contain foreign key of LocTxt nor LocTxt doesn't contain foreign key of Tb.
    So, I need a view, Vw, that joins Tb and LocTxt. In this view Tb records are duplicated, of course. But I read this view always in a user's language context and this removes duplicates.

     

    Now it seems to me that these two classes, Tb and Vw, should be defined separately. The only thing I can to to keep them together is to define an interface containing all common columns.

    What do tou think abolut it?

    Regards
    Tomasz

Back to Top