private void EnsureExisting() { if (!_existingLoaded) { _existingLoaded = true; if (!string.IsNullOrEmpty(Item.Id())) { var aml = Conn.AmlContext; var query = aml.Item(Item.Type(), aml.Id(Item.Id()), aml.Action("get")); if (QueryDefaults != null) { QueryDefaults.Invoke(query); } var items = query.Apply(Conn).Items(); if (items.Any()) { _existing = items.Single(); } else { _existing = Client.Item.GetNullItem <IReadOnlyItem>(); } } else { _existing = Client.Item.GetNullItem <IReadOnlyItem>(); } } }
private void EnsureNewVersion() { if (!_newLoaded) { _newLoaded = true; var props = OldVersion.LazyMap(Conn, i => new { ConfigId = i.ConfigId().Value, Generation = i.Generation().AsInt() }); var aml = Conn.AmlContext; var query = aml.Item(OldVersion.Type(), aml.Action("get"), aml.ConfigId(props.ConfigId), aml.Generation(props.Generation + 1) ); if (QueryDefaults != null) { QueryDefaults.Invoke(query); } _newVersion = query.Apply(Conn).AssertItem(); } }