0

I am creating an MVC ASP.Net application and have a large list of data that I need to display in a table, hoewever, not all data is in one table of my database. Because of this I have created a view model to get all necessary data and put it in one location for my view. This has worked perfectly until recently when I have begun to get large amounts of data. Now the process of moving all data from models to the view model takes too long. Traditionally I would use lazy loading to cut down on this time, but am unsure how to do this with a view model. Is this even possible?

If there is any code that you would like, please let me know, but I'm not sure what code would be necessary right now.

3
  • Take a look at this Commented Dec 20, 2015 at 16:19
  • @Shyju good response on the your link. I gave it an upvote. As for lazy loading from the viewmodel you don't have to do anything extra than normal. Just make sure your navigation properties are virtual and make sure in your configuration class your enable lazy loading (its already enabled by default). Commented Dec 20, 2015 at 16:24
  • That post is explaining about how deferred execution works and how it affects performance (when you have navigation properties which comes from other tables) and a solution to solve that (using dtos and projection) Commented Dec 20, 2015 at 16:26

2 Answers 2

2

From the other answer posted the solution seems to be for your database to:

  var.Resource.Include(s=>s.someResource);

The Include() applies eager loading. Eager loading is the process where a query for one type of entity also loads related entities as part of the query. This will speed it up so you do not make many requests.

Sign up to request clarification or add additional context in comments.

Comments

0

Put this in your DBContext class and install the microsoft.proxis package:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseLazyLoadingProxies().UseSqlServer("Data Source=.;Initial Catalog=Da2;Integrated Security=True");
        }

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.