0

I have a database table called "item" that has a self-referencing field called "itemParentID". When I generate an EDMX and models, I gain access to to "item.item1", which is the parent of the current item and "item.items1", which is a collection of child items. I also have the property "item.itemParentID", but I rarely use it directly.

How do these names "item1" and "items1" get chosen? I generate the EDMX from database and would like for the names to automatically be "topic.Parent" and "topic.Children" so that I would not have to touch the generated code or create additional code in partials.

Joel Peltonen
  • 13,025
  • 6
  • 64
  • 100

2 Answers2

1

That is the logic hardcoded into EDMX generation. The name is inferred from the name of related entity type but it doesn't work very well in case of self referencing relations or multiple relations to to the same type. In such cases the generator will add those numbers to property names.

The only way you can do to fix it is to rename properties in the designer but beware that this is also the only modification which is sometimes lost during updating the model from database.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • I see. Do you think then that my approach of creating an accessor for them in a partial would be a good idea? It would be simple; something like `public Item Parent {get{return Item1;}}` - just to make code readable. – Joel Peltonen Apr 30 '12 at 11:20
  • 1
    But if you want to access those relations in queries or for eager loading you will still have to use original properties because Linq-to-entities cannot use your custom properties from your partial class. – Ladislav Mrnka Apr 30 '12 at 11:42
0

Select the properties in your model ( edmx ) designer and open the properties window.

You can set the names there.

I don't know of a way of changing the names that are automatically generated.

Nick Butler
  • 24,045
  • 4
  • 49
  • 70