Two classes to show data from one Table

4 posts, 0 answers
  1. Alex
    Alex avatar
    5 posts
    Member since:
    Sep 2010

    Posted 23 Sep 2010 Link to this post

    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
    --------------------------------------


  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 24 Sep 2010 Link to this post

    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
  3. DevCraft banner
  4. Alex
    Alex avatar
    5 posts
    Member since:
    Sep 2010

    Posted 24 Sep 2010 Link to this post

    Hello Alexander,

    I am using the visual designer.

    Thank you.
  5. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 28 Sep 2010 Link to this post

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