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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:40:19+00:00 2026-05-19T09:40:19+00:00

I’m trying to figure out the best approach to architecting this project. Basically, it’s

  • 0

I’m trying to figure out the best approach to architecting this project. Basically, it’s a “band” profile site. I’m using ASP.NET 4, EF, and Automapper (structuremap too, but that’s not important). I’m running into performance issues and need advice on whether my approach is right or not (my guess is not). I’ll focus on specific sections and provide stripped down examples.

I have a EntityFramework repository class that interacts directly onto the EF objects using LINQ:

[Pluggable("Repository")]
public class EntityDataRepository : IRepository
{
    static EntityDataRepository()
    {
        // other mappings removed
        // Data. objects are EF objects, mapping to my DTO classes
        Mapper.CreateMap<Data.Event, Models.EventModel>();
        Mapper.CreateMap<Data.Genre, Models.GenreModel>();
        Mapper.CreateMap<Data.Band, Models.BandModel>();
    }

    public IEnumerable<BandModel> GetBandsByUser(Guid userId)
    {
        using (var ctx = new DbContext())
        {
            var user = GetCurrentUserModel(ctx, userId);

            var efBands = from r in user.BandRelations
                            orderby r.Date
                            select r.Band;

            return Mapper.Map<IEnumerable<Data.Band>, IEnumerable<Models.BandModel>>(efBands);
        }
    }
}

Bands have genres and events. Note that it maps the EF objects to my DTO object, and returns a list of them. It acts as a proxy to enable my controllers to invoke methods on to obtain the data that it needs (actual logic altered to show what I need):

namespace OpenGrooves.Web.Areas.Edit.Controllers
{
    [Authorize]
    public class MyBandsController : BaseController
    {
        public ActionResult ShowBands()
        {
            IEnumerable<BandModel> bands = repository.GetBandsByUser(loggedUserGuid).First();

            return View(bands);
        }
    }
}

Finally, here’s the BandModel class, which is mirroring the Band class entity in EF:

public class BandModel
{
    // fluff and scalar properties removed
    public IEnumerable<EventModel> Events { get; set; }
    public IEnumerable<GenreModel> Genres { get; set; }
}

Basically, am I doing this right? In my EF to DTO classes, the Band EF entity has navigational properties, such as Genres and Events. The problem is, during the mapping that takes place in automapper, these list properties are being populated, especially if one of my proxy methods returns a list of BandModels. It seems to be invoking the Genres and Event EF queries for each record, which is a major performance killer obviously (at least 2 queries for Events and Genres are ran for each BandModel object returned).

  • Is it OK practice to use EF objects directly in my controllers, possibly even used as models for views?
  • Is there something I need to change in my mappings to enable lazy loading for these navigational properties (events, genres off a BandModel object)?

Thanks!!

  • 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-19T09:40:20+00:00Added an answer on May 19, 2026 at 9:40 am

    Is it OK practice to use EF objects directly in my controllers, possibly even used as models for views?

    Yes, Kinda.

    This answer is subjective and depends on how you view your separation of concerns. Most MVC developers, including me, swear on view models. It decouples your data or domain classes from the presentation layer. This is awesome.

    Some people don’t like being awesome, including other languages and frameworks like every PHP MVC framework, Rails, and Django. Nobody can say these languages “do it wrong” but us .NET devs subscribe to a different paradigm.


    Your second question is strange you say “is there something to enable lazy loading” right after you say lazy loading is happening. Care to explain?

    Lazy loading is on by default in EF4.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.