Is there any way to control the names of properties generated by the linq-to-sql designer?
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.
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".
精彩评论