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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:43:50+00:00 2026-05-27T18:43:50+00:00

I have a WPF application using MVVM approach. In one of my viewmodels I

  • 0

I have a WPF application using MVVM approach.

In one of my viewmodels I have a private observable collection which I set to a ‘new observableCollection’ which is created from a query which fetches the data via a repository class using an ISession object from NHibernate.

I have a private observable collection in my viewmodel which I want to update with the collection returned/created from my query.

The problem is, every time I call my method to perform the query, the time taken to update the private object ( ObservableCollection ) takes longer every time.

I tested the time taken for the query to execute in the repository and its only 4 or 5 seconds.. I am retrieving 4500 records using lazy loading.

So my question is why would the time increase every time I call my refresh method in the viewmodel? Additionally I should also add that the memory usage shown in task manager also increases so it almost appears there is a memory leak?

Code example below:

ViewModel:

private static ObservableCollection<CustomerViewModel> _allCustomers;      
Expression<Func<Customer, bool>> expression2 = p => p.IsVisible == 'T';

_allCustomers = new ObservableCollection<CustomerViewModel>(
    from customer in ManyEntitiesRepository<Customer>.Instance.RetrieveAll(expression2)
    select new CustomerViewModel(customer));

Repository Retrieve

    public virtual IList<T> RetrieveAll(Expression<Func<T, bool>> expression)
    {
        try
        {
            if (_allEntities != null)
            {
                foreach (T entity in _allEntities)
                    SessionProvider.Instance.GlobalSession.Evict(entity);
                _allEntities.Clear();
            }

            _allEntities = (from c in SessionProvider.Instance.GlobalSession.Query<T>().AsExpandable()
                            where expression.Invoke(c)
                            select c).ToList<T>();

            return _allEntities;
        }
  • 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-27T18:43:51+00:00Added an answer on May 27, 2026 at 6:43 pm

    To workaround this I am looping the viewmodels in my private collection and calling cleanup() on each… adds an extra 4 seconds or so to the refresh but hey its better than having your memory clogged up with duplicate viewmodels and having the query time increase by 20 seconds or more with each refresh.

                        foreach (XViewModel m in _xCollection)
                        {
                            m.Cleanup();
    
                         }
    

    I will keep an eye out for V.4 of the toolkit release in the coming months…

    Cheers

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

Sidebar

Related Questions

I have a C# WPF application using a rather noddy MVVM approach. In one
I have a wpf application using mvvm approach. The main window contains a tab
I have a very simple WPF application in which I am using data binding
I have a WPF application using MVVM. I have some user controls that show
I am coding a WPF application using MVVM pattern. I don't need to have
I have a WPF Microsoft Surface Application and I'm using MVVM-Pattern. I have some
I'm currently introducing Prism to a new Wpf application, and am using the MVVM
I have a WPF application implemented using the MVVM framework that uses an ActiveX
I have a WPF application using MVVM that utilises TreeViewItemViewModels to simplify working with
I am creating a page-based WPF application using MVVM. I have created a custom

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.