有没有办法控制 linq-to-sql 设计器生成的属性名称?

发布于 2024-11-17 01:55:37 字数 665 浏览 2 评论 0原文

假设您有一个看起来像这样的模式,

Foo
    FooId

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

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

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

但是,linq-to 不是生成 SomeFooAnotherFoo 属性,而是生成-sql设计器生成FooFoo1FooFoo1 哪个引用 SomeFoo,哪个引用 AnotherFoo 并不明显。有没有办法手动指定这些属性的名称,以便我可以将它们称为 SomeFooAnotherFoo

我在 Visual Studio 2010 中使用 dbml 设计器,在 Visual Studio 2008 中也遇到了同样的问题。

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);

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?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江湖彼岸 2024-11-24 01:55:37

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

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


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

编辑

我明白了。在 LINQ to SQL 设计器中,单击关联(将两个关联表连接在一起的线),展开“父属性”树并更改 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.

EDIT:

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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文