我正在尝试使用Azure Backend with Sync来为我的应用程序工作。 看起来PullAsync并没有填充我的本地表。
我的表格设置如下:
private IMobileServiceSyncTable<Familie> FamilienTable = App.MobileService.GetSyncTable<Familie>(); // offline sync
首先是一些代码。像这样初始化表:
if (!App.MobileService.SyncContext.IsInitialized)
{
var store = new MobileServiceSQLiteStore("localGarden.db");
store.DefineTable<Familie>();
await App.MobileService.SyncContext.InitializeAsync(store);
}
我可以看到该表已创建,之后它在我的本地系统上(已尝试设置新表)。
稍后在我的代码中,这称为:
try
{
await FamilienTable.PullAsync(null, FamilienTable.CreateQuery());
}
catch (Exception ex)
{
errorString = "Pull failed: " + ex.Message +
"\n\nIf you are still in an offline scenario, " +
"you can try your Pull again when connected with your Mobile Serice.";
}
if (errorString != null)
{
MessageDialog d = new MessageDialog(errorString);
await d.ShowAsync();
}
我最初根据https://material.angularjs.org/latest/demo/virtualRepeat进行了设置并适应了使用Win10 App。这主要是使用Microsoft.Azure.Mobile.Client.SQLitestore 2.0.1。
我知道我需要将PullAsync中的null替换为字符串,以便将来进行增量更新。
使用fiddler我发现在pullAsync期间在Azure上有2次调用我的node.js驱动的API: [已删除] .azurewebsites.net / tables / Familie?$ skip = 0&amp; $ top = 50&amp; __ includeDeleted = true(返回我的表中有6行的JSON)并且在[删除]之后移民.azurewebsites.net / tables / Familie?$ skip = 6&amp; $ top = 50&amp; __ includeDeleted = true,返回一个空的JSON。
我的本地表虽然保持空白。
有人可以告诉我,如果这种行为是设计的,请解释为什么我接到2个电话并告诉我在哪里查找我的本地表未填充的原因?
非常感谢!
CREATE TABLE IF NOT EXISTS [Familie] ([id] INTEGER PRIMARY KEY, [Name] TEXT, [Deleted] BOOLEAN, [Version] DATETIME, [createdAt] DATETIME, [updatedAt] DATETIME)
CREATE TABLE IF NOT EXISTS [__operations] ([id] TEXT PRIMARY KEY, [kind] INTEGER, [state] INTEGER, [tableName] TEXT, [tableKind] INTEGER, [itemId] TEXT, [item] TEXT, [createdAt] DATETIME, [sequence] INTEGER, [version] INTEGER)
CREATE TABLE IF NOT EXISTS [__errors] ([id] TEXT PRIMARY KEY, [httpStatus] INTEGER, [operationVersion] INTEGER, [operationKind] INTEGER, [tableName] TEXT, [tableKind] INTEGER, [item] TEXT, [rawResult] TEXT)
CREATE TABLE IF NOT EXISTS [__config] ([id] TEXT PRIMARY KEY, [value] TEXT)
BEGIN TRANSACTION
INSERT OR IGNORE INTO [__config] ([id]) VALUES (@p0)
The thread 0x2fcc has exited with code 0 (0x0).
UPDATE [__config] SET [value] = @p0 WHERE [id] = @p1
COMMIT TRANSACTION
SELECT * FROM [__operations] ORDER BY [sequence] DESC LIMIT 1
SELECT COUNT(1) AS [count] FROM [__operations]
Pulling changes from remote server
'Gemüsebeetplaner.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\Jens\documents\visual studio 14\Projects\Gemüsebeetplaner\Gemüsebeetplaner\bin\x86\Debug\AppX\System.Linq.Queryable.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
SELECT * FROM [__operations] WHERE ([tableName] = @p1) LIMIT 0
SELECT COUNT(1) AS [count] FROM [__operations] WHERE ([tableName] = @p1)
Pulling changes from remote server
SELECT * FROM [__operations] WHERE ([tableName] = @p1) LIMIT 0
SELECT COUNT(1) AS [count] FROM [__operations] WHERE ([tableName] = @p1)
SELECT * FROM [Familie] ORDER BY [Name]
这是启用参数的日志: 从远程服务器拉取更改
SELECT * FROM [__operations] WHERE ([tableName] = @p1) LIMIT 0
@p1:Familie
SELECT COUNT(1) AS [count] FROM [__operations] WHERE ([tableName] = @p1)
@p1:Familie
{
"count": 0
}
Pulling changes from remote server
SELECT * FROM [__operations] WHERE ([tableName] = @p1) LIMIT 0
@p1:Familie
SELECT COUNT(1) AS [count] FROM [__operations] WHERE ([tableName] = @p1)
@p1:Familie
{
"count": 0
}
SELECT * FROM [Familie] ORDER BY [Name]
The thread 0x24c8 has exited with code 0 (0x0).
The thread 0x1474 has exited with code 0 (0x0).
The thread 0x1a40 has exited with code 0 (0x0).
public class Familie
{
[JsonProperty(PropertyName = "Id")]
public int Id { get; set; }
[JsonProperty(PropertyName = "Name")]
public string Name { get; set; }
}
答案 0 :(得分:0)
执行Pull操作时始终至少有2个调用,因为客户端无法知道服务器批量大小。在您的示例中,服务器发送了6条记录,因此客户端需要执行另一个查询以查明是否有更多记录
没有填充本地表的症状是什么?查询FamilienTable
时会得到空结果吗?
第一次通话是否会返回结果?如果是这样,那么本地数据库的填充方式肯定会有些奇怪。尝试将记录SQLite商店添加到您的应用程序,这将记录所有本地数据库语句,这里有一个示例:https://github.com/Azure-Samples/app-service-mobile-dotnet-todo-list-files/blob/master/src/client/MobileAppsFilesSample/Helpers/LoggingHandler.cs