Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom data store not working #41

Open
schnabs opened this issue Nov 25, 2016 · 1 comment
Open

custom data store not working #41

schnabs opened this issue Nov 25, 2016 · 1 comment

Comments

@schnabs
Copy link

schnabs commented Nov 25, 2016

I've created and registered a Table Data Store.

class ParticipantStore : BaseTableDataStore<Participant>
{
        
        public async Task<IEnumerable<Participant>> GetGameParticipantsAsync(Game game)
        {
            Initialize();
            await Sync();
            return await Table.Where(item => item.GameId == game.Id).ToEnumerableAsync();
        }

    }

public class ParticipantsViewModel : BaseAzureViewModel<Participant> {...}

and replaced

 //client.RegisterTable<Participant>();
 client.RegisterTable<Participant, ParticipantStore>();

Seems to fail when my view models vm.RefreshCommand.Execute(null) gets called

System.NullReferenceException: Object reference not set to an instance of an object.

Also,
Not sure how I can eventually call the GetGameParticipantsAsync(Game game) method I've created in the RefreshCommand because it looks like it only has a getter and no setter.

@KrisWoods
Copy link

KrisWoods commented Jan 24, 2017

@schnabs Are you still having an issue with this? I had the same problem but I got it to work after a couple hours of debugging. It turns out that I needed to use the same client I initialized before I registered my tables on app start, inside the custom data store.

public override void Initialize()
{
if (serviceClient == null)
{
//using the client that I initialized on app start
serviceClient = App.client;
//serviceClient = ServiceLocator.Instance.Resolve();
}
}

	public virtual void Initialize(IEasyMobileServiceClient client)
	{
		//using the client that I initialized on app start
		serviceClient = App.client;
		//serviceClient = client;
	}

Otherwise, this get call for the table will return null:
IMobileServiceSyncTable<Team> table; protected IMobileServiceSyncTable<Team> Table { get { return table ?? (table = serviceClient.MobileService.GetSyncTable<Team>()); } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants