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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:13:19+00:00 2026-05-21T02:13:19+00:00

I’m working to move my simple asp.net website to a three layer architecture. Currently

  • 0

I’m working to move my simple asp.net website to a three layer architecture. Currently I have Linq queries like the one below in my code-behind files. Basically this code snippet retrieves a collection of customer data from the database and then binds it to a grid control.

I’m wondering if someone can guide me on how to rewrite this in order to move it to my newly-created data access layer. I’m thinking I will turn it into a class (e.g. GetUserBoxesByStatus()) that can be reused throughout the site.

            var boxes = from p in sbm.Packages
                    where p.UserID == CurrentUserId && p.StatusID > 1 && p.StatusID < 3
                    select new { p.PackageTag, p.PackageName, p.DateReceived, p.DateShipped };
        GridView1.DataSource = boxes;
        DataBind();

Some of the options that I’ve investigated but have not had success implementing are the following:

  • DataTable — returning a DataTable seems like the best solution but it also appears to require a lot of potentially unecessarry code to define a table (isn’t the data source already mapped in my Linq 2 Entities dbml?)
  • IEneuerable — I think I could pass an IEnumerable list between the layers but after reading many tutorials about Linq I’m still a little lost
  • DTO — Conceptually I think I understand what a DTO is but I am not clear on how to begin implementing this approach
  • POCO — Again, the concept seems logical enough but I don’t know how to put this into practice

    I’m hoping someone here can look at my code example and propose how they would tackle this using one of the above or some other solution.

    • 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-21T02:13:20+00:00Added an answer on May 21, 2026 at 2:13 am

      Create a class with the properties you need. Select into that class. Return a strongly-typed List (so that the query is actually performed in the DAL, not in your view). Bind your data source to the list.

      public class PackageViewModel
      {
         public string Tag { get; set; }
         public string Name { get; set; }
         public DateTime Received { get; set; }
         public DateTime Shipped { get; set; }
      }
      

      DAL

      public List<PackageViewModel> GetUserBoxesByStatus( int userID, int minStatus, int maxStatus )
      {
          return sbm.Packages
                    .Where( p => p.UserID == userID
                                  && p.StatusID > minStatus
                                  && p.StatusID < maxStatus )
                    .Select( p => new PackageViewModel
                     {
                         Tag = p.PackageTag,
                         Name = p.PackageName,
                         Received = p.DateReceived,
                         Shipped = p.DateShipped
                     })
                    .ToList();
      }
      
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

    Sidebar

    Related Questions

    I have just tried to save a simple *.rtf file with some websites and
    link Im having trouble converting the html entites into html characters, (&# 8217;) i
    I want use html5's new tag to play a wav file (currently only supported
    Seemingly simple, but I cannot find anything relevant on the web. What is the
    this is what i have right now Drawing an RSS feed into the php,
    Does anyone know how can I replace this 2 symbol below from the string
    I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
    That's pretty much it. I'm using Nokogiri to scrape a web page what has
    I want to count how many characters a certain string has in PHP, but
    I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

    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.