You have a number of options available, depending on which machine you want the burden of ordering.
1. You can create a Stored Procedure on the DB server which will SELECT * FROM ... ORDER BY ...
and use that in your .dbml
2. You mentioned you are using Linq to SQL classes generated from a .dbml, so I am going on the assumption you are using LinqDataSource
in your .aspx pages.
From within your designer, you can select Configure Data Source on your LinqDataSource
:
Then you choose your Context from your .dbml, and on the next screen you have the option to Order By:
3. Using Dynamic Data Web Site you do not have the advantage of a specific table structure at design time. Because of this, you need to create a sort that will happen at runtime. You can edit your DynamicData\PageTemplates\List.aspx.cs
to include the following:
protected void Page_Load(object sender, EventArgs e)
{
Title = table.DisplayName;
// Disable various options if the table is readonly
if (table.IsReadOnly)
{
GridView1.Columns[0].Visible = false;
InsertHyperLink.Visible = false;
GridView1.EnablePersistedSelection = false;
}
// Add our sort to the first data column.
if (!Page.IsPostBack)
{
GridView1.Sort(table.Columns[0].Name, SortDirection.Ascending);
}
}