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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:13:56+00:00 2026-05-13T21:13:56+00:00

In my service layer for my MVC application I am attempting to convert the

  • 0

In my service layer for my MVC application I am attempting to convert the linq to sql entity results into my business model entities. I am currently attempting the following code:

    public IList<Project> GetAllProjects()
    {
        var results = from p in _context.Repository<DBMappings.project>()
                      select p;

        foreach (DBMappings.project prj in results.ToList<DBMappings.project>())
            yield return CreateProjectEntityFromDBProject(prj);

    }

Unfortunately, this doesn’t seem to work and the only thing I can guess is that yield only works with IEnumerable. Is there any other solution besides creating a new list, adding items in the foreach loop and returning the list? I need to use an IList because methods that use the returned list need to be able to do List Methods such as .Sort().

  • 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-13T21:13:56+00:00Added an answer on May 13, 2026 at 9:13 pm

    if you want to .Sort() you should definitely create a list in your method. using yield saves you some memory – because results are not stored as a single object. This is useful when you just want to walk over results. but if you want to Sort something you need it in memory as a single piece.

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

Sidebar

Related Questions

I'm developing an application with a service layer that operates on a domain model.
I have an asp.net mvc application with three layers: - data layer with entities
I have an application that is currently divided into Service and Data Access Layers
I have a MVC application with a Domain Model well defined, with entities, repositories
suppose you have an MVC application with the Model represented by an Entity Framework
The service layer of my ASP.NET MVC 3 application uses AutoMapper to map view
I'm using LINQ to Entities in the Data layer of my application, but am
How would one typically implement a service layer in an MVC architecture? Is it
I have this sort of format asp.net MVC View -> Service Layer -> Repository.
use Service layer to persist data into database. But the Unit Test does not

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.