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 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

Ask A Question

Stats

  • Questions 343k
  • Answers 343k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I know this is not the answer, but I'd suggest… May 14, 2026 at 5:25 am
  • Editorial Team
    Editorial Team added an answer I just tried active: false and it worked... May 14, 2026 at 5:25 am
  • Editorial Team
    Editorial Team added an answer +(float)getTotalDiskSpaceInBytes { float totalSpace = 0.0f; NSError *error = nil;… May 14, 2026 at 5:25 am

Related Questions

I've really been struggling to make SQL Server into something that, quite frankly, it
I have a SQL database that has several hundred tables in it, but I
Im trying to work out the best way scale my site, and i have
I have two issues both related to (I believe) my SQL Server setup. I
I am developing a report in Sql Server Reporting Services 2005, connecting to an

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.