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

  • Home
  • SEARCH
  • 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 537479
In Process

The Archive Base Latest Questions

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

I have to work with multiple SQL Server tables that generally look like this:

  • 0

I have to work with multiple SQL Server tables that generally look like this:

int id_this, int id_that, ..., double Value1, double Value2, ..., double Value96

I know this sucks, but I can’t change it. What I want to do now is to define some class like

public class Foo
{
    public int Id_This { get; set; }
    public int Id_That { get; set; }
    ...
    public double Value[];
}

The Value-Array being a property of course, but I think you get the idea.

The question is, how to get the 96 columns into the array as painlessly as possible.

I could do that with a plain SqlDataReader, since DataRow allows indexed access, but I wonder if I could declare some attributes or write some minimum amount of code to use the class directly with LINQ2SQL.

As a minimum, I would like to do

dataContext.ExecuteQuery<Foo>("SELECT * FROM Foo");
  • 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-13T09:55:53+00:00Added an answer on May 13, 2026 at 9:55 am

    Ooh, that is… nice? The DataContext methods always expect an entity type; there is no ExecuteReader, which is a pain (but understandable, as it wants to behave as an ORM). To be honest, I would be tempted to use ADO.NET for the guts against this table, but if you have mapped the wide table to the DataContext you should be able to use either regular C# or reflection.

    Since the number doesn’t change, unless you have multiple tables I’d just bite the bullet and write some ugly code:

    Foo foo = new Foo { Id_This = obj.Id_This, Id_That = obj.Id_That,
        Values = new double[] {obj.Value1, obj.Value2, ... } };
    

    If you have multiple tables… reflection, perhaps optimised via Expression:

    using System;
    using System.Collections.Generic;
    using System.Linq.Expressions;
    class FooUgly
    {
        public int IdThis { get; set; }
        public int IdThat { get; set; }
        public double Value1 { get; set; }
        public double Value2 { get; set; }
        public double Value3 { get; set; }
    }
    class Foo
    {
        public int IdThis { get; set; }
        public int IdThat { get; set; }
        public double[] Values { get; set; }
        public Foo() { }
        internal Foo(FooUgly ugly)
        {
            IdThis = ugly.IdThis;
            IdThat = ugly.IdThat;
            Values = extractor(ugly);
        }
        // re-use this!!!
        static readonly Func<FooUgly, double[]> extractor =
            ValueExtractor<FooUgly, double>.Create("Value", 1, 3);
    }
    static class Program
    {
        static void Main()
        {
            FooUgly ugly = new FooUgly { IdThis = 1, IdThat = 2, Value1 = 3, Value2 = 4, Value3 = 5 };
            Foo foo = new Foo(ugly);
        }
    }
    static class ValueExtractor<TFrom,TValue>
    {
        public static Func<TFrom, TValue[]> Create(string memberPrefix, int start, int end)
        {
            if(end < start) throw new ArgumentOutOfRangeException();
            ParameterExpression param = Expression.Parameter(typeof(TFrom), "source");
            List<Expression> vals = new List<Expression>();
            for(int i = start ; i <= end ; i++) {
                vals.Add(Expression.PropertyOrField(param, memberPrefix + i));
            }
            Expression arr = Expression.NewArrayInit(typeof(TValue), vals);
            return Expression.Lambda<Func<TFrom, TValue[]>>(arr, param).Compile();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At work, we have multiple branches that we may be working on at any
I just wonder what the best approach is to have multiple users work on
Here at work we have a very large application with multiple sub applications. (500
In Team Foundation Server is there a way to have work items in one
I have to work on some code that's using generic lists to store a
Sometimes I have to work on code that moves the computer clock forward. In
I am writing controls that work nice with JavaScript, but they have to work
I have to work on an old 1.3 JVM and I'm asked to create
I have to work on several VB6 legacy projects and despite some good VB6
Lucky me, I have to work with Oracle. And packages. I have a package

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.