ASP.NET 动态数据 DisplayColumn 属性导致排序问题

发布于 2024-07-16 12:52:48 字数 632 浏览 6 评论 0原文

将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦开始←不甜 2024-07-23 12:52:48

这是正确的,因为该属性不在数据库中,并且 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.

酸甜透明夹心 2024-07-23 12:52:48

这可能是设计使然...

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

鹤仙姿 2024-07-23 12:52:48

您可以尝试重写可能有效的 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.

咿呀咿呀哟 2024-07-23 12:52:48

尝试添加 [ScaffoldColumn(true)] - 它可能会欺骗动态数据以启用排序

[DisplayColumn("LastNameFirstName", "LastName", false)]
public partial class Employee
{
    [ScaffoldColumn(true)]
    public string LastNameFirstName
    {
        get { return LastName + ", " + FirstName; }
    }
}

Try adding [ScaffoldColumn(true)] - it might trick dynamic data to enable sorting

[DisplayColumn("LastNameFirstName", "LastName", false)]
public partial class Employee
{
    [ScaffoldColumn(true)]
    public string LastNameFirstName
    {
        get { return LastName + ", " + FirstName; }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文