How do I access the data from my domain service in my view model ? Silverlight 5 application

68 Views Asked by At

I am a beginner in Silverlight and I just started to get used to it, but now I have a problem. In my StudentDomainService I have this method that returns all of my students:

public IEnumerable<Student> GetStudents()
    {
        return _studentService.GetStudents();
    }

StudentService is a class from the business part of my application (I have a project and I have to follow some requirements, one of them is to have the business solution that contains StudentModel, StudentRepository and StudentService). In the .web solution I have the StudentDomainService that has access to my StudentService class. The problem is that in the View Model I have this method:

 public void LoadStudents()
    {
       _studentDomainContext.GetStudents();
    }

But obviously this is wrong because it does absolutely nothing and I know the problem is that I don't use the domain contex in the right way, but I don't know how to fix this and I would appreciate if someone could tell me how to do this correctly. Thank you!

1

There are 1 best solutions below

4
Nkosi On

Have a local member to store the value.

private List<Student> students;

//...

public void LoadStudents() {
    // get data
    var data = _studentDomainContext.GetStudents();
    students = data.ToList();

    //...
}

From there it is up to you how you want to expose or use that value.