views:

136

answers:

1

Hi. 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

+2  A: 

_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

Veer
I tried _followersRepo.Load(_followersRepo.GetUsersFollowingIDQuery(CurrentUserId)); Followers = new ObservableCollection<aspnet_User>(_followersRepo.aspnet_Users); _followingRepo.Load(_followingRepo.GetUsersFollowedByIDQuery(CurrentUserId)); Following = new ObservableCollection<aspnet_User>(_followingRepo.aspnet_Users); _fullUserRepo.Load(_fullUserRepo.GetFullUserByIDQuery(CurrentUserId)); CurrentUser = _fullUserRepo.FullUsers.SingleOrDefault();but that doesn't seem to work either. Is it before Followers is instantiated at all?
Jakob
please post the code for any of the Load method. Else check if the method loads some data into _followersRepo.aspnet_users.
Veer
I've checked it and they don't. public IQueryable<aspnet_User> GetUsersFollowingID(Guid userid) { return this.DataContext.Followers.Where(f => f.FollowedId == userid).Select(f => f.aspnet_User1); }
Jakob
@Jakob: This returns an IQueryable<aspnet_User> to the Load method. Now what does your Load method do? Remember, IQueryable is not executed until you call the enumerator. Instead of adding the code in comments area use the edit option in your question:) Add codes for Load method especially.
Veer
should i add .GetEnumerator() then?
Jakob
@Jakob: As I said earlier, post your code for Load method to get a big picture.
Veer
I'm not sure I follow, If I haven't presented the load method I'm not sure what to give you, It's probably that I'm not getting. Can you help me to understand what you need from me?
Jakob
@Jakob: Check my edit. If `filteredFollwers` doesn't have any data, then there is some problem with the service that is providing the data.
Veer