Hi,
I wrote this code which worked with th db18 version of couchbase Lite 2.0, .net c# :
document = new Document("airline_88888");
airline = new Airline();
airline.Type = "airline";
airline.Id = 88888;
airline.Name = "Steeve";
airline.Country = "France";
document.Set("airline_88888", airline);
DatabaseSd.Save(document);
Since the bd19 vresion, I’ve an exception when I try to save the document :
$exception {System.InvalidCastException: Cannot encode Persistance.Airline to Fleece!
at LiteCore.Interop.FLSliceExtensions.FLEncode(Object obj, FLEncoder* enc)
at LiteCore.Interop.FLSliceExtensions.FLEncode[TVal](IDictionary`2 dict, FLEncoder* enc)
at Couchbase.Lite.Internal.Doc.InMemoryDictionary.FLEncode(FLEncoder* enc)
at LiteCore.Interop.FLSliceExtensions.FLEncode(Object obj, FLEncoder* enc)
at Couchbase.Lite.Document.Encode()
at Couchbase.Lite.Document.SaveInto(C4Document** outDoc, Boolean deletion)
at Couchbase.Lite.Document.Save(IConflictResolver resolver, Boolean deletion)
at Couchbase.Lite.Document.b__23_0()
at Couchbase.Lite.Support.ThreadSafety.DoLocked(Action a)
at Couchbase.Lite.Document.Save()
at Couchbase.Lite.Database.<>c__DisplayClass64_0.b__0()
at Couchbase.Lite.Support.ThreadSafety.DoLocked(Action a)
at Couchbase.Lite.Database.Save(Document document)
at Persistance.CouchbaseHelper.AddAirlineDocument(Airline airline, Database db)
at CouchBaseT2.MainPage.BtnAdd_Clicked(Object sender, EventArgs e)
at Xamarin.Forms.Button.SendClicked()
at Xamarin.Forms.Platform.UWP.ButtonRenderer.OnButtonClick(Object sender, RoutedEventArgs e)} System.InvalidCastException
Here is my Airline Class :
public partial class Airline
{
[JsonProperty("callsign")]
public string Callsign { get; set; }
[JsonProperty("country")]
public string Country { get; set; }
[JsonProperty("iata")]
public string Iata { get; set; }
[JsonProperty("icao")]
public string Icao { get; set; }
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
[JsonIgnore]
public string Infos { get => $"{Id} - {Country} - {Name}"; }
}
How to save a document ?
Regards
Steeve