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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:29:51+00:00 2026-05-11T17:29:51+00:00

We decided to use Linq To SQL for our Data Layer on our most

  • 0

We decided to use Linq To SQL for our Data Layer on our most recent project. We have a functional solution, that so far has handled everything we have thrown at it, with one major problem. We have to code the same method over and over again to retrieve just slightly different result sets from our database.

As an example:

        public List<TeamBE> GetTeamsBySolutionID(Guid SolutionID)
        {
            List<TeamBE> teams = new List<TeamBE>();

            Esadmin db = new Esadmin(_connectionString);

            var qry = (from teamsTable in db.Teams
                       join solutionsTable in db.Solutions on teamsTable.SolutionID equals solutionsTable.SolutionID
                       where teamsTable.SolutionID == SolutionID
                       select new { teamsTable, solutionsTable.SolutionName });

            foreach (var result in qry)
            {
                TeamBE team = new TeamBE();

                team.TeamID = result.teamsTable.TeamID;
                team.Description = result.teamsTable.Description;
                team.Status = result.teamsTable.Status;
                team.LastModified = result.teamsTable.LastModified;
                team.SolutionID = result.teamsTable.SolutionID;
                team.SolutionName = result.SolutionName;
                team.Name = result.teamsTable.Name;
                team.LocationLevel = result.teamsTable.LocationLevel;
                team.AORDriven = result.teamsTable.AoRDriven;
                team.CriteriaID = result.teamsTable.CriteriaID ?? Guid.Empty;

                teams.Add(team);
            }
            return teams;
        }

        public TeamBE GetTeamByID(Guid TeamID)
        {
            Esadmin db = new Esadmin(_connectionString);
            TeamBE team = new TeamBE();

            var qry = (from teamsTable in db.Teams
                       join solutionsTable in db.Solutions on teamsTable.SolutionID equals solutionsTable.SolutionID
                       where teamsTable.TeamID == TeamID
                       select new { teamsTable, solutionsTable.SolutionName }).Single();

            team.TeamID = qry.teamsTable.TeamID;
            team.Description = qry.teamsTable.Description;
            team.Status = qry.teamsTable.Status;
            team.LastModified = qry.teamsTable.LastModified;
            team.SolutionID = qry.teamsTable.SolutionID;
            team.SolutionName = qry.SolutionName;
            team.Name = qry.teamsTable.Name;
            team.LocationLevel = qry.teamsTable.LocationLevel;
            team.AORDriven = qry.teamsTable.AoRDriven;
            team.CriteriaID = qry.teamsTable.CriteriaID ?? Guid.Empty;

            return team;
        }

And on and on ad nauseum.

Is there is a way to pass Linq results as a parameter to a function, so I can place my object mappings in one function, and not repeat myself so much?

  • 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-11T17:29:51+00:00Added an answer on May 11, 2026 at 5:29 pm

    I took a quick stab at it. Probably doesn’t compile (Especially the “from teamsTalbe in teams), but the idea is you can factor out something that returns an IQueryable<>. You’re IQueryable returns an anonymous type though, which wouldn’t work. So you may need to create an explicit type to use in place of ‘select new { teamsTable, solutionsTable.SolutionName }’

        public List<TeamBE> GetTeamsBySolutionID(int solutionID)
        {
            Esadmin db = new Esadmin(_connectionString);
            return GetTeamsBy(db, _GetTeamsBySolutionID(db, solutionID));
        }
    
        IQueryable<Team> _GetTeamsBySolutionID(Esadmin db, int solutionID)
        {
            return from teamsTable in db.Teams
                   where teamsTable.SolutionID == SolutionID
                   select teamsTable;
        }
    
        List<TeamBE> GetTeamsBy(Esadmin db, IQueryable<Team> teams)
        {
            List<TeamBE> teams = new List<TeamBE>();
    
            var qry = (from teamsTable in teams
                       join solutionsTable in db.Solutions on teamsTable.SolutionID equals solutionsTable.SolutionID
                       select new { teamsTable, solutionsTable.SolutionName });
    
            foreach (var result in qry)
            {
                TeamBE team = new TeamBE();
    
                team.TeamID = result.teamsTable.TeamID;
                team.Description = result.teamsTable.Description;
                team.Status = result.teamsTable.Status;
                team.LastModified = result.teamsTable.LastModified;
                team.SolutionID = result.teamsTable.SolutionID;
                team.SolutionName = result.SolutionName;
                team.Name = result.teamsTable.Name;
                team.LocationLevel = result.teamsTable.LocationLevel;
                team.AORDriven = result.teamsTable.AoRDriven;
                team.CriteriaID = result.teamsTable.CriteriaID ?? Guid.Empty;
    
                teams.Add(team);
            }
            return teams;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I decided to use LINQ to SQL in my personal project after hearing lots
I am working on a database access layer project and decided to use Linq
After too much thought, I've decided to use Linq To SQL as a DAL
I decided to use log4net as a logger for a new webservice project. Everything
We decided to use the minimumRequiredVersion in our clickOnce application manifest, and now when
I started a Rails project recently and decided to use RESTful controllers. I created
I'm writing some data analysis software and decided to use such approach: epn: model/data.py
I've been developing a site using ASP.NET MVC, and have decided to use the
Since I'm using Postgresql and can't use LINQ to SQL, I wrote my own
Greetings, I have a few applications/websites running with LINQ to SQL and the other

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.