I got on a big enough project and the task was to add just one bool property to my DTO model and consume it in my mobile application. It was said that on backend this property had already been added so everything should work fine.
But I have such a problem. Suppose RemoteTable is defined as following:
protected IMobileServiceTable<T> RemoteTable;
and initialized in constructor from injected MobileServiceClient as following:
RemoteTable = mobileClient.GetTable<T>();
And if I'm trying to get all entities like this:
IMobileServiceTableQuery<T> remoteQuery = predicate != null
? RemoteTable.CreateQuery().Where(predicate)
: RemoteTable.CreateQuery();
remoteItems = await remoteQuery.ToCollectionAsync(PageSize);
or any similar way like:
var allItems = await RemoteTable.ToEnumerableAsync();
In those cases my entities do NOT have that property. Actually I have this Exception:
Newtonsoft.Json.JsonSerializationException: 'Error converting value {null} to type 'System.Boolean'. Path '[0].IsRecommended'.'
So I made my property nullable not to have this Exception to be able to test the app and figure out what's wrong. And I kept receiving null every time EXCEPT THE FOLLOWING CASE:
// suppose I already have entity myEntity taken from previous steps
// now the magic begins
myEntity = await RemoteTable.LookupAsync(myEntity.Id);
Now I have full entity without null in my bool? property (now it contains true/false as expected).
So the question is: what's wrong and where to look for it? Why is it that I cannot get all entities with that boolean property being set, but I can if searching just one entity by its id?
Short version - you have updated the backend service but not the underlying database.
You need to add the field to the database table, then update every single record to ensure the value is populated. It's the case of executing a migration - or just doing the ADJUST TABLE / UPDATE TABLE commands via SQL.