Domain model: Best practise for self referencing

5 posts, 0 answers
  1. Stefan Lorenz
    Stefan Lorenz avatar
    13 posts
    Member since:
    May 2010

    Posted 22 Jul 2010 Link to this post

    Hi,

    I wonder how to build tree-like structures with the visual designer. I've did this before using old forward-mapping, but have no luck with the visual designer so far. Here's an example of the table and class I'd created with forward-mapping:

    dbo.treeitem
    ->Id
    ->name
    ->parentId

    class TreeItem
    {
      string Name
      TreeItem Parent
    }

    If I move the table to the visual designer, parentId of course is an Int32 (as the table-field is Int32), but it should map to the class' type in code instead.

    Edit: I've found the solution! I removed the mapping, added a constraint (parentId->Id) under model scheme and mapped the table again. Now the visual designer shows a Parent:TreeItem and a Treeitems-Collection of children.

    Best Regards
    Stefan
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 22 Jul 2010 Link to this post

    Hello Stefan Lorenz,

    You can also do the following - map the class to a table, select the Association item from the toolbox and click twice on the class in the diagram. A dialog will pop up where you can choose your foreign key and primary key properties for the association. Hope that helps.

    Sincerely yours,
    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. Stefan Lorenz
    Stefan Lorenz avatar
    13 posts
    Member since:
    May 2010

    Posted 23 Jul 2010 Link to this post

    Hi Alexander,

    I tried it the way you described. The designer added the TreeItems-Collection, but the Parent-Property is missing.

    Edit: Creating the constraint before adding the association did the trick. So the clue is to manually add the constraint and then either unmap/map or add an association the way you've suggested.

    Stefan
  5. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 29 Jul 2010 Link to this post

    Hi Stefan Lorenz,

    I tried to reproduce the problem but with no success. Having a constraint or not should not reflect the way associations are created. Please note that the name of the parent property may not be the one that you expect, in such case you can rename it manually.
    If the property is really missing, we would like to know a bit more information about your setup. Does this happen with every table or only with the first one you tried? If this is observed only with particular table, please send us its definition so we can try to reproduce the described behavior.

    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
  6. Stefan Lorenz
    Stefan Lorenz avatar
    13 posts
    Member since:
    May 2010

    Posted 29 Jul 2010 Link to this post

    Hi Alexander,

    I tried it again and now it works. Unfortunately I can't say what changes to the model or database made a change to this phenomenon. If I ever see this again, I'll make a snapshot of the state.

    Thanks for your effort

    Stefan
Back to Top
DevCraft banner