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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:23:07+00:00 2026-05-19T03:23:07+00:00

Good day! I’ve a legacy application where data access layer consists of classes where

  • 0

Good day!

I’ve a legacy application where data access layer consists of classes where queries are done using SqlConnection/SqlCommand and results are passed to upper layers wrapped in untyped DataSets/DataTable.

Now I’m working on integrating this application into newer one where written in ASP.NET MVC 2 where LINQ2SQL is used for data access. I don’t want to rewrite fancy logic of generating complex queries that are passed to SqlConnection/SqlCommand in LINQ2SQL (and don’t have permission to do this), but I’d like to have result of these queries as strong-typed objects collection instead of untyped DataSets/DataTable.

The basic idea is to wrap old data access code in a nice-looking from ASP.NET MVC “Model”.

What is the fast\easy way of doing this?

Additionally to the answer below here is a nice solution based on AutoMapper: http://elegantcode.com/2009/10/16/mapping-from-idatareaderidatarecord-with-automapper/

  • 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-19T03:23:07+00:00Added an answer on May 19, 2026 at 3:23 am

    An approach that you could take is using the DataReader and transfer. So for every object you want to work with define the class in a data transfer object folder (or however your project is structured) then in you data access layer have something along the lines of the below.

    We used something very similar to this in a project with a highly normalized database but in the code we did not need that normalization so we used procedures to put the data into more usable objects. If you need to be able to save these objects as well you will need handle translating the objects into database commands.

    What is the fast\easy way of doing
    this?

    Depending on the number of classes etc this is could not be the fastest approach but it will allow you to use the objects very similarly to the Linq objects and depending on the type of collections used (IList, IEnumerable etc) you will be able to use the extension methods on those types of collections.

    public IList<NewClass> LoadNewClasses(string abc)
    {
        List<NewClass> newClasses = new List<NewClass>();
    
        using (DbCommand command = /* Get the command */)
        {
            // Add parameters
            command.Parameters["@Abc"].Value = abc;
    
            // Could also put the DataReader in a  using block
            IDataReader reader = /* Get Data Reader*/;
    
            while (reader.Read())
            {
                NewClass newClass = new NewClass();
                newClass.Id = (byte)reader["Id"];
                newClass.Name = (string)reader["Name"];
    
                newClasses.Add(newClass);
            }
    
            reader.Close();
        }
    
        return newClasses;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day everyone. I have a question about making and using derived classes of
Good day! I am using Xcode 3.1.4 and iPhone SDK 2.2.1. I am creating
Good day. I'm confused about storing the embedded database in a Java EE application.
Good day everyone! I am using the T-SQL ISDATE() function with a date column
good day, I am using Joomla 1.5 and wanted to make a real estate
Good day! I am trying to disable access on pages that are not part
Good day, We just converted our web application .NET 1.1 to .NET 2.0. We
Good day! How is the confirmation for deletion usually done in Web-based applications? I
Good day! I tried using JSTL in java but there's an error: exception javax.servlet.ServletException:
Good day :) I am using jQuery's animate() on both opacity and height, on

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.