有什么方法可以控制linq-to-sql设计器生成的属性的名称? [英] Is there any way to control the names of properties generated by the linq-to-sql designer?

查看:70
本文介绍了有什么方法可以控制linq-to-sql设计器生成的属性的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有一个类似以下的模式

Say you have a schema that looks something like this

Foo
    FooId

Bar
    BarId
    SomeFooId // Foreign key to Foo.FooId
    AnotherFooId // Foreign key to Foo.FooId

我希望能够执行以下操作:

I would like to be able to do something like this:

Bar bar = ...
DoSomethingWith(bar.SomeFoo);
DoSomethingElseWith(bar.AnotherFoo);

但是,不是生成 SomeFoo 和<在code> AnotherFoo 属性中,linq-to-sql设计器生成 Foo Foo1 Foo Foo1 中哪个引用 SomeFoo ,并引用 AnotherFoo 。有什么方法可以手动为这些属性指定名称,以便我可以将它们称为 SomeFoo AnotherFoo

However, instead of generating SomeFoo and AnotherFoo properties, the linq-to-sql designer generates Foo and Foo1. It is not obvious which of Foo and Foo1 refers to SomeFoo, and which refers to AnotherFoo. Is there any way to manually specify a name for these properties, so that I can refer to them as SomeFoo and AnotherFoo?

我在Visual Studio 2010中使用dbml设计器,而Visual Studio 2008也有相同的问题。

I am using the dbml designer in Visual Studio 2010, and I had the same problem with Visual Studio 2008.

推荐答案

您可以在Linq to SQL设计器中编辑名称。只需单击要重命名的字段,按 F4 ,然后更改 Name 属性。

You can edit the names in the Linq to SQL designer. Just click on the field you want to rename, press F4, and change the Name Property.

或者,您可以单击要重命名的字段,然后开始输入新名称。

Alternatively, you can click on the field you want to rename, and just start typing the new name.

因此,您要修改为外键生成的便利属性的名称。

So you want to modify the names of the "convenience properties" that are generated for the foreign keys.

编辑

我知道了。在LINQ to SQL设计器中,单击关联(将两个关联表连接在一起的行),展开父属性树,并更改 Name 属性。这将影响便利属性的生成名称。

I figured it out. In the LINQ to SQL designer click on the association (the line connecting the two associated tables together), expand the "Parent Property" tree and change the Name Property. This will affect the generated name of the "convenience property".

这篇关于有什么方法可以控制linq-to-sql设计器生成的属性的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆