ASP.NET 动态数据 DisplayColumn 属性导致排序问题
将 ASP.NET 动态数据与 Northwind 数据库中的 LINQ to SQL DataContext 结合使用...
当我将 DisplayColumn 属性添加到我的 LINQ to SQL entity
类之一并引用来自我的自定义代码的属性时部分类,我失去了在生成的 GridView 中按该列排序的能力。 即使我将非自定义属性引用为 sortColumn
,我仍然无法进行排序。
为什么会发生这种情况?
示例代码:
[DisplayColumn("LastNameFirstName", "LastName", false)]
public partial class Employee
{
public string LastNameFirstName
{
get { return LastName + ", " + FirstName; }
}
}
Aaron
编辑: sortColumn
指定当实体用作外键(在 DropDownList 中)时将用于对此实体进行排序的列,而不是当它用作外键时。正在 GridView 中排序。
Using ASP.NET Dynamic Data with a LINQ to SQL DataContext from the Northwind Database...
When I add a DisplayColumn Attribute to one of my LINQ to SQL entity
classes and reference a property from my custom code in the partial class, I lose the ability to sort by that column in the generated GridViews. I continue to lose the ability to sort even if I reference a non-custom property as the sortColumn
.
Why is this happening?
Example Code:
[DisplayColumn("LastNameFirstName", "LastName", false)]
public partial class Employee
{
public string LastNameFirstName
{
get { return LastName + ", " + FirstName; }
}
}
Aaron
EDIT: The sortColumn
specifies the column that will be used to sort this entity when it is used as a foreign key (in a DropDownList), not when it is being sorted in the GridView.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是正确的,因为该属性不在数据库中,并且 linq to SQL 将尝试构造一个到数据库的 T-SQL 查询来获取您的实体。 但会失败,因为这些不是具有该名称的列。
That is correct because the property is not in the DB and linq to SQL will try to construct a T-SQL quert to the DB to get your entities. but will fail because these is no column with that name.
这可能是设计使然...
“sortColumn”指定当实体用作外键(在 DropDownList 中)时将用于对该实体进行排序的列,而不是在 GridView 中对其进行排序时。
This may be by Design...
The "sortColumn" specifies the column that will be used to sort this entity when it is used as a foreign key (in a DropDownList), not when it is being sorted in the GridView.
您可以尝试重写可能有效的 ToString() 方法,但它只会过滤 FK 关系引用的实体。
You could try overriding the ToString() method that might work but it would only filter on the entity referenced by the FK relationship.
尝试添加 [ScaffoldColumn(true)] - 它可能会欺骗动态数据以启用排序
Try adding [ScaffoldColumn(true)] - it might trick dynamic data to enable sorting