有没有办法控制 linq-to-sql 设计器生成的属性名称?
假设您有一个看起来像这样的模式,
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 不是生成 SomeFoo
和 AnotherFoo
属性,而是生成-sql设计器生成Foo
和Foo1
。 Foo
和 Foo1
哪个引用 SomeFoo
,哪个引用 AnotherFoo
并不明显。有没有办法手动指定这些属性的名称,以便我可以将它们称为 SomeFoo
和 AnotherFoo
?
我在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 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".