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

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

2 Answers 63 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.
tmlipinski
Top achievements
Rank 1
tmlipinski asked on 10 Mar 2009, 10:28 AM
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 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 13 Mar 2009, 02:53 PM
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.
0
tmlipinski
Top achievements
Rank 1
answered on 13 Mar 2009, 04:24 PM
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

Tags
General Discussions
Asked by
tmlipinski
Top achievements
Rank 1
Answers by
PetarP
Telerik team
tmlipinski
Top achievements
Rank 1
Share this question
or