0

I'm taking a stab at the model first approach and I am running into an annoyance. If I have an entity named Building with a key property named BuildingID, for example, and I create an association to a Room entity, the foreign key property in the Room entity ends up being named BuildingBuildingID.

How can I stop this madness!

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Erik
  • 279
  • 1
  • 3
  • 14
  • What is gained by naming the PK of Building as BuildingID instead of just ID. In the code you will access this as objectName.ID anyway and with intellisense it would be obvious that objectName is of type Building. – softveda Jul 07 '12 at 01:18

1 Answers1

1

Visual Studio will take a stab at choosing the best name for the association key. By default, I believe, it is <EntityName><EntityKeyName>, thus BuildingBuildingId in your case. However, because the conceptual model is separate from the storage model, you can rename that property to anything you want it to be.

Also, if you are using the association wizard screen in Visual Studio, and you do not want VS to create a new foreign key. There is a box you can uncheck to prevent it from creating the property.

Brian Knight
  • 4,970
  • 28
  • 34
  • So, there is no way to change a setting to take the entity's key name as the foreign key name? I know I can edit it, but I have better things to do with the 5 seconds! :) – Erik Jul 05 '12 at 20:00
  • By default, not that I am aware of in model first. If you import your schema through the wizard, it should bring in the name of your foreign key field, which you can then assign as the association key in lieu of having the tool create a new one for you. – Brian Knight Jul 05 '12 at 20:04