Visual Studio C# Change entity variables names for dbml file

813 views Asked by At

I know how to create Foreign Key in sql express and how to use dbml file and it's entities, But I like to change the name of a variable in one of my entities.

Let me explain this:

Lets think I have a Table named "Person" and this table has a Foreign Key to itself like parent and child. Now in C# I can use this syntax to get father of a child:

Person child = getSomePerson();
Person father = child.Person;

But I like to do something Like this:

Person child = getSomePerson();
Person father = child.father;

So what should I do to change default name "Person" To what I like it to be?

Edit 1:

It is better if I can do it with a sql query in sql server so I dont have to change anything in my C# project.

1

There are 1 answers

3
Gert Arnold On BEST ANSWER

I'd not really recommend it, but if you insist, you can edit the dbml file itself (the XML) in a text editor and change the name of the reference property.

You'll see a line like (guessing a bit)

<Association Name="Person_Person" Member="Person" ThisKey="ParentId" OtherKey="PersondD" Type="Person" IsForeignKey="true" />

Now change Member="Person" into Member="Father". (I'd use Pascal case, not "father").

Then open the dbml file in designer mode (the default way), press "Save" (to trigger code generation) and the navigation property will have been changed.

Note that this change will obviously be gone if you'd have to regenerate your dbml in the future (because of db changes). You may consider moving to Entity Framework, where making such changes is natural.