Jakob
Jakob

Reputation: 4854

Why doesn't my viewmodel properties get populated

I've looked all over and I can't figure out why my viewmodel doesn't get populated.

I have this code:

_followersRepo = new NotesDomainContext(); 
_followersRepo.Load(_followersRepo.GetFollowersQuery(), lo => { 
_followers = new ObservableCollection(_followersRepo.aspnet_Users); 
    }, null); 

_followingRepo = new NotesDomainContext(); 
_followingRepo.Load(_followingRepo.GetUsersFollowedByIDQuery(CurrentUserId), lo => {
 _following = new ObservableCollection(_followingRepo.aspnet_Users); 
}, null); 

_fullUserRepo = new NotesDomainContext(); 
_fullUserRepo.Load(_fullUserRepo.GetFullUserByIDQuery(CurrentUserId), lo => {
 _currentUser = _fullUserRepo.FullUsers.SingleOrDefault(); 
}, null);

But when I debug, there is no data loaded to the Followers, Following and CurrentUser objects. I know that data should be returned because I'm trying to implement the MVVM pattern in my app, and haven't changed the domainservice. Also I can se debugging the CurrentUserId has a value. None of the variables have a value though, and the repo's don't have any either.

When I try to view the value of i.e. _followersRepo.aspnet_Users i just get "enumeration yielded no results" what's up with that?

There must be some key logic about domainservice querying that I'm really not getting, so I would appreciate it very much if someone would open my eyes

Upvotes: 0

Views: 542

Answers (1)

Amsakanna
Amsakanna

Reputation: 12954

_followersRepo.Load(_followersRepo.GetUsersFollowingIDQuery(CurrentUserId));

If this line is used to load data into _followersRepo, it should be before instantiating Followers.

Update

Try this:

_followersRepo = new NotesDomainContext();
var filteredFollowers = _followersRepo.GetFollowersQuery(); // That should return you an IQueryable<aspnet_User>
_followers = new ObservableCollection(filteredFollowers); // An ObservableCollection is created out of the IQueryable<aspnet_User>

No need to create the _followersRepo again. use the same instance for creating other collections also

Upvotes: 2

Related Questions