Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 199015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:59:13+00:00 2026-05-11T16:59:13+00:00

I have a view in my database that produces ordered results, but when I

  • 0

I have a view in my database that produces ordered results, but when I run a Linq query over that view, the results are no longer ordered (at least, according to the foreach I use to iterate over the results, and according to the debugger). Is this a known difficulty with Linq, or am I missing something?

Update: my view, from SQL Server 2008 (from design view):

SELECT     TOP (100) PERCENT UrlId, Title, Description, Url, Parent, ResourceKey, Published, dbo.udf_SiteMap_GetRoles(UrlId) AS Roles
FROM         dbo.SiteMap
ORDER BY DisplayOrder

The Linq query that builds the SiteMap:

SqlConnection connection = new SqlConnection(_connect);
DataContext dc = new DataContext(connection);
Table<NodeRoleEntity> siteMapTable = dc.GetTable<NodeRoleEntity>();

var rootQuery = from ne in siteMapTable
                where ne.ParentID == null
                select ne;
foreach (NodeRoleEntity rootNode in rootQuery)
{
   SiteMapNode root = rootNode.AsSiteMapNode(this);
   base.AddNode(root, _root);
   AddChildNodes(root, siteMapTable);
}  

This query uses the SiteMap built above to render menus in my ASP.NET application:

StaticSiteMapProvider _provider = SiteMap.Providers["MySiteMap"] as StaticSiteMapProvider;
string cultureToken = _GetCulture().ToLower();
SiteMapNode cultureRoot = 
    (from SiteMapNode cr in _provider.RootNode.ChildNodes
     where cr.Description == cultureToken
     select cr).First();

int menuCount = 0;            
foreach (SiteMapNode node in cultureRoot.ChildNodes)
{
   _RenderMenu(node, menuCount.ToString(), writer);
   menuCount++;
}  

It is the nodes in cultureRoot.ChildNodes that are ordered improperly (but the rows from which those nodes are derived are ordered).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:59:13+00:00Added an answer on May 11, 2026 at 4:59 pm

    When you select from a view it doesn’t keep it’s order. You have to put in in the LINQ:

    SiteMapNode cultureRoot = (
       from SiteMapNode cr in _provider.RootNode.ChildNodes
       where cr.Description == cultureToken
       orderby cr.DisplayOrder
       select cr
    ).First();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have gwt-project that is comunication to database. Application design mvp pattern and view
Im create this code to store page view in database, but i have problem
I have setup a database view. When users import the data from the view
I have a Monthly Status database view I need to build a report based
I have a name of table or view in PostgreSQL database and need to
A simple question: I have a Model-View-Controller setup, with Models accessing a SQL database.
i have view like 'home/details/5', it can be access by anonymous user. but there
I have a list view which is populated via records from the database. Now
I have created a java SE application that uses the mysql database using mysql
I’ve got an SQLite database that will need to contain products. Those products have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.