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 961495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:21:13+00:00 2026-05-16T01:21:13+00:00

As it stands now, the CLR UDTs including HierarchyID aren’t supported in Entity Framework

  • 0

As it stands now, the CLR UDTs including HierarchyID aren’t supported in Entity Framework 4. HierarchyID.ToString() is useful, but breaks down once any item has 10+ siblings (the basic structure is /3/4/12/ or /3/4/2/ so the 12th node will sort before the 2nd node).

A little more about potential options:

  • Bring back hierarchyID as a varbinary and implement my own binary sorter

  • Bring back hierarchyID as a varbinary and implement my own hierarchyID.ToString() method which pads the numbers with zeros while building the string so the resulting string is sortable (i.e. “/0003/0004/0012/”). I disassebled Microsoft.SqlServer.Types.dll and looked at the implementation. It looks like the interals are based of a class called “OrdTree” and I could use that class as a basis for re-implementation.

  • Write my own CLR type for SQL to work on the binary data and build its own string (a variation of option 2). Although, comes with an added deployment headache.

  • Write a SQL udf to parse the hierarchy string and pad it on the DB layer. The lack of array processing/regex’s seems like the biggest issue here.

  • Sort by hierarchyID on the database layer and use the ROW_NUMBER() function as a stand in for sort order.

  • Write some helper methods on the .net layer which re-parse the hierarchyId.ToString() and generate a sortable string (i.e. “/0003/0004/0012/”).

So my question is has anyone worked around the limitation? Did you use any of the above strategies? If so, how?

  • 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-16T01:21:14+00:00Added an answer on May 16, 2026 at 1:21 am

    Well, I seem to be getting views but no responses. I had some immediate needs to work with the hierarchy structure above SQL, so i put together a static helper class. I don’t consider this a complete solution, but so far it works relatively well. PadPath is really the critical function here.

    public static class SQLHierarchyManipulatin {
        const int   DEFAULT_PAD_LEN     = 3;
        const char  DEFAULT_PAD_CHAR    = '0';
    
        public static string PadPath(string Hierarchy) {
            return PadPath (Hierarchy, DEFAULT_PAD_LEN);
        }       
        public static string PadPath(string Hierarchy, int padLen) {
            string[]    components  = Hierarchy.Split('/');
    
            for (var i = 0; i < components.Length; i++ ) {
                if (components[i] != "") {
                    components[i] = components[i].PadLeft(padLen, DEFAULT_PAD_CHAR);
                }
            }
            return string.Join("/", components);
        }
    
        public static int CurrentNodeIndex(string Hierarchy) {
            string[]    components  = Hierarchy.Split('/');
            string      startItem   = components[components.Length - 2]; //one slot back from trailing slash
    
            return int.Parse(startItem);
        }
    
        public static string ParentPath (string Hierarchy) {
            return  Hierarchy.Substring(0, Hierarchy.TrimEnd('/').LastIndexOf('/') + 1);
        }
    
        public static string AppendChildWithPadding (string Hierarchy, int childIndex, int padLen) {
            return AppendChild(Hierarchy, childIndex, DEFAULT_PAD_LEN);
        }
        public static string AppendChildWithPadding (string Hierarchy, int childIndex) {
            return AppendChild(Hierarchy, childIndex, DEFAULT_PAD_LEN);
        }
        public static string AppendChild (string Hierarchy, int childIndex) {
            return AppendChild(Hierarchy, childIndex, DEFAULT_PAD_LEN);
        }
        public static string AppendChild (string Hierarchy, int childIndex, int padLen) {
            return Hierarchy + childIndex.ToString().PadLeft(padLen, DEFAULT_PAD_CHAR) + "/";
        }
    }
    

    Hope this helps someone! Although, I’d still like to hear from people.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As it stands now, I'm a Java and C# developer. The more and more
I know asp stands for Active Server Pages but wondering if Active Server means
I'm working on an application that uses WPF and WCF. As it stands now,
I'm just curious what Afx stands for. And what about Fx in FxCop?
What is a .snk file for? I know it stands for Strongly Named Key
Is there any substantial difference between those two terms?. I understand that JDK stands
I am reusing a curl function from a long time ago that is now
I know Rake stands for Ruby Make, and I know Make is a unix
Is there a stand-alone GUI designer that can read and write the .form files
Can I load an stand alone aspx page in another stand alone aspx page

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.