App-Service-Helpers icon indicating copy to clipboard operation
App-Service-Helpers copied to clipboard

custom data store not working

Open schnabs opened this issue 9 years ago • 1 comments

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.

schnabs avatar Nov 25 '16 21:11 schnabs

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

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

KrisWoods avatar Jan 24 '17 04:01 KrisWoods