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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:07:11+00:00 2026-05-29T15:07:11+00:00

I am currently working with EnterpriseLibrary 5.0 and MVVM: I have an ObservableCollection ListCategories<Category>

  • 0

I am currently working with EnterpriseLibrary 5.0 and MVVM:

I have an ObservableCollection ListCategories<Category> property binded to an editable ComboBox (I can add/delete/edit categories):

I have the following code:

public ObservableCollection<Category> ListCategories
        {
            get
            {
                return listCategories;
            }

            set
            {
                listCategories = value;
            }
        }
    var categories = sdb.ExecuteSprocAccessor <Category> ("Get_Categories_List");

                 ListCategories = categories.ToObservableCollection <Category>();

My question:

After all changes made in the collection, how to update back the database?

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-29T15:07:12+00:00Added an answer on May 29, 2026 at 3:07 pm

    The proper way is to have a DB Access layer behind the Repository pattern of:

    public interface IRepository<T>
    {
       IEnumerable<T> GetAll();
       T GetById(int id);
       void Save(T saveThis);
       void Delete(T deleteThis);
    }
    

    then implement this with your domain type Category (I’m assuming that’s a domain type and not a type generated by an ORM.

    public interface ICategoryRepository : IRepository<Category>
    {
        // add any methods that are needed to act on this specific repo
    }
    

    then set the dependency in the ViewModel to this ICategoryRepository;

    private readonly ICategoryRepository _categoryRepo;
    
    public ViewModel(ICategoryRepository categoryRepo)
    {
        _categoryRepo = categoryRepo;
    }
    

    Then act on this dependency from your ViewModel, your ViewModel SHOULD NOT be calling a database directly which is what you seem to be implying.

    your code:

    sdb.ExecuteSprocAccessor <Category> ("Get_Categories_List");
    

    should reside in the GetAll() of the repository. Move it out of the ViewModel.

    your setting of the observable collection should be done in the ctr:

    ListCategories = categories.ToObservableCollection <Category>();
    

    to this:

    public ViewModel(ICategoryRepository categoryRepo)
    {
        _categoryRepo = categoryRepo;
        var categories = _categoryRepo.GetAll();
        ListCategories = categories.ToObservableCollection <Category>();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`m currently working on a script, and I have the following situation. function somnicefunction()
Im currently working on a site that you can upload large files.. on local
Currently working through a Teach Yourself WPF tutorial. Usually I can mentally convert from
I am currently working on a C# project where I have 3 separate projects
Currently working on a 3D media engine using C# and I have come across
Currently working on trying to figure out asynchronous submission in ColdFusion. I always have
I currently working with PictureBox and facing one problem. First, I have drawn one
Currently working on rails 3. I made changes in my css file to add
Currently working on a bespoke ecommerce application using Codeigniter. I have a products table
Currently working in the deployment of an OFBiz based ERP, we've come to the

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.