且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

LINQ to SQL:如何使用列别名扩展实体类

更新时间:2023-02-13 16:08:35

LINQ不知道将Id转换为WidgetId.

LINQ doesn't know to translate Id to WidgetId.

在O/R设计器中,您可以将列重命名为所需的列.当您这样做时,LINQ将能够正确转换列名.在O/R设计器中重命名它们根本不会影响数据库,因此这是一个非常安全的操作.您可以打开.designer.cs文件,并查看如何使用属性"将列名映射到类属性.

In the O/R designer you can rename the columns to whatever you need them to be. When you do this, LINQ will be able to properly translate the column names. Renaming them in the O/R designer doesn't affect the database at all, so it is a perfectly safe operation. You can open the .designer.cs file and see how the Attributes are used to map column names to class properties.