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

Domain model: Best practise for self referencing

4 Answers 102 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stefan Lorenz
Top achievements
Rank 1
Stefan Lorenz asked on 22 Jul 2010, 09:31 AM
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

4 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 22 Jul 2010, 04:37 PM
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
0
Stefan Lorenz
Top achievements
Rank 1
answered on 23 Jul 2010, 08:10 AM
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
0
Alexander
Telerik team
answered on 29 Jul 2010, 10:10 AM
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
0
Stefan Lorenz
Top achievements
Rank 1
answered on 29 Jul 2010, 10:33 AM
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
Tags
Getting Started
Asked by
Stefan Lorenz
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Stefan Lorenz
Top achievements
Rank 1
Share this question
or