Is there any way to control the names of properties generated by the linq-to-sql designer?

可紊 提交于 2019-12-13 05:20:11

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/6471330/is-there-any-way-to-control-the-names-of-properties-generated-by-the-linq-to-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!