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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:00:52+00:00 2026-05-12T17:00:52+00:00

I have been doing this: public List<Role> GetRoles() { List<Role> result = new List<Role>();

  • 0

I have been doing this:

        public List<Role> GetRoles()
    {
        List<Role> result = new List<Role>();

        foreach (var r in Db.tblRoles)
        {
            result.Add(new Role()
            {
                Description = r.d,
                Id = r.Id,
                Responsibility = r.Responsibility
            });

        }
        return result;
    }

I have a lot of table that map 1:1 with my object model, is there a better way to get my table data into my om?

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

    Much easier using the Select() and ToList() extension methods.

     public List<Role> GetRoles()
     {
          return Db.tblRoles
                   .Select( r => new Role
                    {
                         Description = r.d,
                         Id = r.Id,
                         Responsibility = r.Responsibility
                    })
                   .ToList();
     }
    

    Or you could simply rename tblRoles to be Roles in the designer as well as rename the properties — if you are ok with treating your LINQ entities as your business entities — and simply do:

     public List<role> GetRoles()
     {
           return Db.Roles.ToList();
     }
    

    The latter is what I typically do, providing my business logic in a separate partial class implementation of the entity using the partial method hooks provided by the designer-generated code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Still learning JSP Web Applications here. I have been doing this for a while
Since the advent of AS3 I have been working like this: private var loggy:String;
I have been doing a bit of research on this but, I am having
Im doing something like this to get a list of all users that have
I'm new to web services in general and have been doing a lot of
I have been doing some research on test driven development and find it pretty
I have been doing active development in C# for several years now. I primarily
I have been doing TDD and was using it more as unit testing than
I have been doing PHP stuff for almost one year and I have never
I have been doing a lot of unit testing lately with mocking. The one

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.