ASP.NET Dynamic Data DisplayColumn Attribute Causing Sorting Issue

我只是一个虾纸丫 提交于 2019-12-05 18:24:31

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.

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.

You could try overriding the ToString() method that might work but it would only filter on the entity referenced by the FK relationship.

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; }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!