MikeCodesDotNET / App-Service-Helpers

Add data storage and authentication to your app in a few lines of code.
MIT License
79 stars 28 forks source link

custom data store not working #41

Open schnabs opened 7 years ago

schnabs commented 7 years ago

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 commented 7 years ago

@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>()); } }