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

Two classes to show data from one Table

3 Answers 51 Views
Databases and Data Types
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alex
Top achievements
Rank 1
Alex asked on 23 Sep 2010, 07:00 PM
Hello, 

I have a Table Person with the fields:
IdPerson | Name | Birthday | Street | City | State | ZIPCode | ...

I would like to create the class Person, but separate the address data in a different Class. Is it possible with Telerik ORM?

----------------------------
Person ( Id, Name, Birthday)
|
hasAddress
|
Address( Street, City, State, ZIPCode) and Probably IdPerson to relate the classes
--------------------------------------


3 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 24 Sep 2010, 04:38 PM
Hi Alex,

I am afraid that mapping two persistent classes to the same table is not possible. You can however, create a View in the database that exposes the Address-part of the columns and create a persistent class against this view. You will be also able to create a relationship between the two classes.
Please let us know if you need more details on how to accomplish this and tell us whether you are using the new visual designer or the "classic" wizards.

Greetings,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alex
Top achievements
Rank 1
answered on 24 Sep 2010, 04:50 PM
Hello Alexander,

I am using the visual designer.

Thank you.
0
Alexander
Telerik team
answered on 28 Sep 2010, 03:42 PM
Hi Alex,

There is not so much to be done but here are the steps:
 - Create a view in the database and include the columns you want to be mapped to the new class;
 - Use the Update from Database wizard to update the domain model and include the newly created view;
 - Now you should be able to see the view in the Model Schema Explorer pane. Just drag it to the design surface and a new persistent class will be created;
 - If you save the diagram, an error should be shown that the new class does not have an identity member. In order to work correctly OpenAccess requires that all persistent classes in the model have identity members. So you will have to manually set one or more properties as identity members for the new class. The requirement is that the identity member (or the combination of several identity members) can identify uniquely each persistent object. In your case the IdPerson column should be enough if the Person - Address relation is one-to-one. You can follow this article in order to resolve the validation error.

Hope that helps.

Kind regards,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Databases and Data Types
Asked by
Alex
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Alex
Top achievements
Rank 1
Share this question
or