简体   繁体   English

Visual Studio C#更改dbml文件的实体变量名称

[英]Visual Studio C# Change entity variables names for dbml file

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. 我知道如何在sql express中创建外键,以及如何使用dbml文件及其实体,但是我想更改一个实体中变量的名称。

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. 假设我有一个名为“ Person”的表,该表本身具有一个外键,例如父级和子级。 Now in C# I can use this syntax to get father of a child: 现在在C#中,我可以使用以下语法来生孩子:

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? 因此,我应该怎么做才能将默认名称“ Person”更改为我喜欢的名称?

Edit 1: 编辑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. 如果我可以使用sql server中的sql查询来执行此操作,则更好,这样我就不必在C#项目中进行任何更改。

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. 我并不是真的推荐这样做,但是如果您坚持要这么做,则可以在文本编辑器中编辑dbml文件本身(XML)并更改reference属性的名称。

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" . 现在将Member="Person"更改为Member="Father" (I'd use Pascal case, not "father"). (我会使用Pascal的情况,而不是“父亲”)。

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. 然后以设计器模式(默认方式)打开dbml文件,按“保存”(触发代码生成),导航属性将被更改。

Note that this change will obviously be gone if you'd have to regenerate your dbml in the future (because of db changes). 请注意,如果将来必须重新生成dbml,则此更改显然将消失(由于db更改)。 You may consider moving to Entity Framework, where making such changes is natural. 您可以考虑移至Entity Framework,在此进行更改是很自然的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM