h b*_*bob 3 c# azure azure-mobile-services
我在Azure的移动应用服务SDK中使用了离线同步功能.
我知道最近SDK中有各种变化.我想根据最新规范定义客户端模型,但不确定使用哪种类型.
这些是脱机同步元数据属性,通常见于大多数示例/教程中:
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
[Version]
public string Version { get; set; }
[CreatedAt]
public DateTimeOffset CreatedAt { get; set; }
[UpdatedAt]
public DateTimeOffset UpdatedAt { get; set; }
[Deleted]
public bool Deleted { get; set; }
Run Code Online (Sandbox Code Playgroud)
但是一些文档和示例,以及GitHub上的各种官方(太多!)样本/快速入门,使用了多种类型的组合.
所以我也在不同的地方看过这个:
[JsonProperty(PropertyName = "id")]
public Guid Id { get; set; } // Guid is used here, not string
[Version]
[JsonProperty(PropertyName = "version")] // Needed? I assume the attribute is enough
public byte[] Version { get; set; } // byte[] is used here, not string
Run Code Online (Sandbox Code Playgroud)
在封面下,一切都是通过REST调用完成的,因此也就是字符串.所以我假设客户端SDK执行各种类型的转换.
但是,当事情发生变化时,我不希望我的应用程序在未来某个时刻莫名其妙地轰炸.那么我应该使用哪种官方支持的类型?
客户端SDK只需要一个字符串Id字段(应该命名为"Id",除非你想要跳过一堆箍).字符串的值可以是任何唯一的字符串.默认情况下,服务器SDK使用字符串转换的GUID.使用脱机同步时,除非指定了ID,否则客户端SDK还会生成字符串GUID.使用在线 IMobileServiceTable API时,客户端允许服务器生成ID.
其余字段是可选字段,应该具有您列出的类型,或者可以转换为它们.
这是您的数据模型,其中包含对各个字段的评论:
// required, should be called Id, *must* be of type string when using offline sync
// When not using offline sync, should be string-convertible.
// When using offline sync, the client SDK uses a new string-converted GUID for this, unless
// an ID is specified.
// When using offline sync, Ids are not mutable, so use something that can be client generated
public string Id { get; set; }
// optional. Using a Version field opts you into optimistic concurrency, where
// the server will reject updates that are done against an older version
// of an object. This means you need a conflict handler.
// To use a client-wins policy, remove this property from your client object
[Version]
public string Version { get; set; }
// optional. Cannot be set on the client, will be sent from the server
[CreatedAt]
public DateTimeOffset CreatedAt { get; set; }
// optional. Cannot be set on the client, will be sent from the server
[UpdatedAt]
public DateTimeOffset UpdatedAt { get; set; }
// should generally not be used in the client object at all. This field tracks
// which objects have been deleted so that they are automatically purged
// from the client's offline sync store
[Deleted]
public bool Deleted { get; set; }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
380 次 |
| 最近记录: |