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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:52:37+00:00 2026-05-13T21:52:37+00:00

I’m trying to define a new type and have not had much luck finding

  • 0

I’m trying to define a new type and have not had much luck finding any information about using lists within them. Basically my new type will contain two lists, lets say x and y of type SqlSingle (the user defined type is written in C#) is this even possible?

If not how are you supposed to go about simulating a two lists of an arbitary length in an SQL Server 2008 column?

I’m possibly going about this the wrong way but it is the best approach I can think of at the moment. Any help is very much appreciated.

  • 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-13T21:52:37+00:00Added an answer on May 13, 2026 at 9:52 pm

    You can use a List<T> in a CLR UDT – although CLR types are structs, which should be immutable, so a ReadOnlyCollection<T> would be a better choice if you don’t have a very compelling reason for the mutability. What you need to know in either case is that SQL won’t know how to use the list itself; you can’t simply expose the list type as a public IList<T> or IEnumerable<T> and be on your merry way, like you would be able to do in pure .NET.

    Typically the way to get around this would be to expose a Count property and some methods to get at the individual list items.

    Also, in this case, instead of maintaining two separate lists of SqlSingle instances, I would create an additional type to represent a single point, so you can manage it independently and pass it around in SQL if you need to:

    [Serializable]
    [SqlUserDefinedType(Format.Native)]
    public struct MyPoint
    {
        private SqlSingle x;
        private SqlSingle y;
    
        public MyPoint()
        {
        }
    
        public MyPoint(SqlSingle x, SqlSingle y) : this()
        {
            this.x = x;
            this.y = y;
        }
    
        // You need this method because SQL can't use the ctors
        [SqlFunction(Name = "CreateMyPoint")]
        public static MyPoint Create(SqlSingle x, SqlSingle y)
        {
            return new MyPoint(x, y);
        }
    
        // Snip Parse method, Null property, etc.
    }
    

    The main type would look something like this:

    [Serializable]
    [SqlUserDefinedType(Format.UserDefined, IsByteOrdered = true, MaxByteSize = ...)]
    public struct MyUdt
    {
        // Make sure to initialize this in any constructors/builders
        private IList<MyPoint> points;
    
        [SqlMethod(OnNullCall = false, IsDeterministic = true, IsPrecise = true)]
        public MyPoint GetPoint(int index)
        {
            if ((index >= 0) && (index < points.Count))
            {
                return points[index];
            }
            return MyPoint.Null;
        }
    
        public int Count
        {
            get { return points.Count; }
        }
    }
    

    If you need SQL to be able to get a sequence of all the points, then you can add an enumerable method to the sequence type as well:

    [SqlFunction(FillRowMethodName = "FillPointRow",
        TableDefinition = "[X] real, [Y] real")]
    public static IEnumerable GetPoints(MyUdt obj)
    {
        return obj.Points;
    }
    
    public static void FillPointRow(object obj, out SqlSingle x, out SqlSingle y)
    {
        MyPoint point = (MyPoint)obj;
        x = point.X;
        y = point.Y;
    }
    

    You might think that it’s possible to use an IEnumerable<T> and/or use an instance method instead of a static one, but don’t even bother trying, it doesn’t work.

    So the way you can use the resulting type in SQL Server is:

    DECLARE @UDT MyUdt
    SET @UDT = <whatever>
    
    -- Will show the number of points
    SELECT @UDT.Count
    
    -- Will show the binary representation of the second point
    SELECT @UDT.GetPoint(1) AS [Point]
    
    -- Will show the X and Y values for the second point
    SELECT @UDT.GetPoint(1).X AS [X], @UDT.GetPoint(1).Y AS [Y]
    
    -- Will show all the points
    SELECT * FROM dbo.GetPoints(@UDT)
    

    Hope this helps get you on the right track. UDTs can get pretty complicated to manage when they’re dealing with list/sequence data.

    Also note that you’ll obviously need to add serialization methods, builder methods, aggregate methods, and so on. It can be quite an ordeal; make sure that this is actually the direction you want to go in, because once you start adding UDT columns it can be very difficult to make changes if you realize that you made the wrong choice.

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

Sidebar

Related Questions

I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have thousands of HTML files to process using Groovy/Java and I need to
I have a view passing on information from a database: def serve_article(request, id): served_article
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

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.