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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:38:50+00:00 2026-05-14T20:38:50+00:00

I used this side to create my demo application http://windowsclient.net/learn/video.aspx?v=314683 The site was very

  • 0

I used this side to create my demo application
http://windowsclient.net/learn/video.aspx?v=314683

The site was very useful in getting my started and in their example, they created a file called EmployeeRepository.cs which appears to be the source for the data. In their example, the data was hard-wired in code. So I’m trying to learn how to get the data from a data source (like a DB). In my specific case, I want to get the data from a Microsoft Access DB. (READ ONLY, So I’ll only use SELECT commands).

using System.Collections.Generic;
using Telephone_Directory_2010.Model;

namespace Telephone_Directory_2010.DataAccess
{
    public class EmployeeRepository
    {
        readonly List<Employee> _employees;

        public EmployeeRepository()
        {
            if (_employees == null)
            {
                _employees = new List<Employee>();
            }
            _employees.Add(Employee.CreateEmployee("Student One", "IT201", "Information Technology", "IT4207", "Building1", "Room650"));
            _employees.Add(Employee.CreateEmployee("Student Two", "IT201", "Information Technology", "IT4207", "Building1", "Room650"));
            _employees.Add(Employee.CreateEmployee("Student Three", "IT201", "Information Technology", "IT4207", "Building1", "Room650"));
        }

        public List<Employee> GetEmployees()
        {
            return new List<Employee>(_employees);
        }
    }
}

I found another example where an Access DB is used but it doesn’t comply with MVVM. So I was trying to figure out how to add the DB file to the project, how to wire it up and bind it to a listbox (i’m not that far yet). Below is my modified file

using System.Collections.Generic;
using Telephone_Directory_2010.Model;
// integrating new code with working code
using Telephone_Directory_2010.telephone2010DataSetTableAdapters;
using System.Windows.Data;

namespace Telephone_Directory_2010.DataAccess
{
    public class EmployeeRepository
    {
        readonly List<Employee> _employees;

        // start
        // integrating new code with working code
        private telephone2010DataSet.telephone2010DataTable employeeTable;
        private CollectionView dataView;
        internal CollectionView DataView
        {
            get
            {
                if (dataView == null)
                {
                    dataView = (CollectionView) CollectionViewSource.GetDefaultView(this.DataContext);
                }
                return dataView;
            }
        }

        public EmployeeRepository()
        {
            if (_employees == null)
            {
                _employees = new List<Employee>();
            }
            telephone2010TableAdapter employeeTableAdapter = new telephone2010TableAdapter();
            employeeTable = employeeTableAdapter.GetData();
            this.DataContext = employeeTable;
        }

        public List<Employee> GetEmployees()
        {
            return new List<Employee>(_employees);
        }
    }

}

I get the following error messages when building

Error 1 ‘Telephone_Directory_2010.DataAccess.EmployeeRepository’ does not contain a definition for ‘DataContext’ and no extension method ‘DataContext’ accepting a first argument of type ‘Telephone_Directory_2010.DataAccess.EmployeeRepository’ could be found (are you missing a using directive or an assembly reference?) C:\Projects\VS2010\Telephone Directory 2010\Telephone Directory 2010\DataAccess\EmployeeRepository.cs 23 90 Telephone Directory 2010

  • 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-14T20:38:51+00:00Added an answer on May 14, 2026 at 8:38 pm

    The MVVM-pattern should suggest three layers:

    Model (=Data-access): Retrieve data from database, here should be your EmployeeRepository. I would recommend not to use any view-specific components here, i.e. no CollectionView. Better just put your employees in a List or ObservableCollection.

    ViewModel: Here you can prepare your data for the view or implement commands, which can be used by the view to retrieve or manipulate data etc.
    In your example this should be some EmployeeViewModel, that retrieves all the employees from the DataAccess-Layer and makes them available as public property, such that the view can bind to it. Do not put database-specific code here, that should completely be contained in the data-access-layer.

    View: Your employee-View containing all the UI-stuff, buttons and all this. And of course you can put some datagrid or ItemsControl here, which binds to the ViewModel and displays its data. The datacontext of your view should be your ViewModel, at least that’s the most common way how to do it.

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

Sidebar

Related Questions

I used this code in my Android application: import org.apache.http.client.methods.HttpPost; ... HttpClient httpclient =
I used this example : http://woork.blogspot.com/2007/10/insert-record-into-database-using-ajax.html it is working when using with Numbers for
I used this script to create a jQuery accordion. Check out the working jsFiddle
I would like to create a site-wide hash to be used as salt in
The <a> tag is used to create hyperlinks but in this age of jQuery
starting from this point: http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system I'm trying to create an application to save a
We are adapting our client side relatively complicated application (ActiveX / .net / Delphi
I used this question/answer to install DB2 in Lion: How do I install IBM
I used this code to compare two NSNumber objects, but it never passed the
I used this code to change the annotation's color,but after that,the title and subtitle

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.