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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:55:20+00:00 2026-05-15T14:55:20+00:00

I am new to C# and this may end up being a dumb question

  • 0

I am new to C# and this may end up being a dumb question but i need to ask anyway.

Is there a mechanism with C# to deserialize a result from an executed SQL statement into a c# object?

I have a C# program that reads a table from an sql server storing the row in an object – i am assigning each column value to an object member manually so i was wondering if there is a way to serialize the row automagically into an object. Or even better, a whole table in a collection of objects of the same type.

My environment is C#, VS2010, .NET4, SQLServer2008.
The assumption is that i know the columns i need, it’s not a select * query.

A link to a neat example will also be appreciated.

Thanks.

  • 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-15T14:55:21+00:00Added an answer on May 15, 2026 at 2:55 pm

    If the columns named as per the table names, you can do this with LINQ-to-SQL without any mapping code – just using ExecuteQuery:

    using(var dc = new DataContext(connectionString)) {
        var objects = dc.ExecuteQuery<YourType>(sql); // now iterate object
    }
    

    Additionally, the sql can be automatically parameterized using string.Format rules:

    class Person {
        public int Id {get;set;}
        public string Name {get;set;}
        public string Address {get;set;}
    }
    using(var dc = new DataContext(connectionString)) {
        List<Person> people = dc.ExecuteQuery(@"
              SELECT Id, Name Address
              FROM [People]
              WHERE [Name] = {0}", name).ToList(); // some LINQ too
    
    }
    

    Of course, you can also use the VS tools to create a typed data-context, allowing things like:

    using(var dc = new SpecificDataContext(connectionString)) {
        List<Person> people =
             (from person in dc.People
              where person.Name == name
              select person).ToList();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this may sound a newbie question anyway Im new to GCD, I'm creating and
This may sound a newbie question however I'm new to iOS dev. Are there
This may be a silly question, but as someone relatively new to PHP, I'm
im really new to linq-to-SQL so this may sound like a really dumb question,
This may end up being a trivial question - I know I'm going to
This may be the wrong place but this is new to me. I did
This may well be simple, but I'm new to Drupal. The organization I work
Ok, this may have been answered, but I'm new and trying to learn, so
I'm new to C++, so this may be a noobish question; I have the
This may end up being a much simpler problem than I'm making it out

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.