有什么方法可以控制linq

编程入门 行业动态 更新时间:2024-10-25 09:27:20
本文介绍了有什么方法可以控制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 和 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

本文发布于:2023-11-12 01:01:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580058.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么   方法   linq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!