0

I have a mobile app build with Xamarin Forms and I'm using Offline Data Sync in Azure Mobile Apps, to enable offline sync in my mobile application

so, I have two tables

  • PurchaseOrders
  • PurcahseOrderDetails

    public IMobileServiceSyncTable<PurchaseOrders> PurchaseOrdersTable;
    public IMobileServiceSyncTable<PurchaseOrderDetails> PurchaseOrderDetailsTable;
    

and I want to sync the records in the PurchaseOrders Table based on UserId

and then sync the records in PurchaseOrderDetails Table based on Id of PurcahseOrder

To do that I'm trying this

Get Purchase Orders based on User Id

var purchaseOrders = (await GetAllPurchaseOrdersAsync(syncFromServer:true, userId)).ToList();

// in sync method 
await PurchaseOrdersTable.PullAsync(queryName, PurchaseOrdersTable.CreateQuery().Where(w => w.Userid == userId));

When I'm trying to get Purchase Order Details based on Id in the list of PurchaseOrders

await PurchaseOrderDetailsTable.PullAsync(queryName,
                         PurchaseOrderDetailsTable.CreateQuery().Where(pod => purchaseOrders.Any(po => po.Id == pod.PoId)));

I get the exception below

'value(System.Collections.Generic.List`1[ProjectName.Models.PurchaseOrder]).Any(po => (po.Id == pod.PoId))' is not supported in a 'Where' Mobile Services query expression.

Can I get an explanation about the error above and how to solve it?

Anas Alweish
  • 2,818
  • 4
  • 30
  • 44
  • 1
    How is the relationship between `PurchaseOrder` and `PurchaseOrderDetail` defined? – Ryan Hill Jul 30 '19 at 23:24
  • @RyanHill-MSFT Thanks for your reply, I'm working on an old project which doesn't contain a relationship between `PurchaseOrders` and `PurchaseOrderDetails` – Anas Alweish Jul 31 '19 at 05:28

1 Answers1

1

If your mobile data is backed by table service, then Any is not a supported LINQ operator (see: https://learn.microsoft.com/en-us/rest/api/storageservices/query-operators-supported-for-the-table-service) so that might be source of the exception.

Since PurchaseOrder doesn't contain a collection of PurchaseOrderDetail, one workaround I can think of is to iterate on purchaseOrders and select from purchaseOrderDetails.

var poDetails = new List<PurchaseOrderDetail>();
foreach (var po in purchaseOrders)
{
   var poDetail = await PurchaseOrderDetails.PullAsync(queryName, PurchaseOrderDetailsTable.CreateQuery().Where(pod => po.Id == pod.PoId);
   poDetails.Add(poDetail);
}
Ryan Hill
  • 1,821
  • 2
  • 8
  • 21