'm migrating data that was previously “float?” and IList<float?" to the type “string” and “IList”. I am attaching the code that performs this migration, and everything goes well when I give a DynamicApi.GetList in an IEmbeddedObject, however, when I call a DynamicApi.GetList in a “float?” gives the error “KeyNotFoundException: The given key ‘’ was not present in the dictionary”. him being the “float?” type. The error only happens when I try to call a GetList in the “MeasuredValues” field, the rest of the code works fine and performs the correct conversion. Does anyone have an idea what I might be doing wrong? See the error that appears:
See how MeasuredValues is in the database, it appears in the scope as List but it is a List<float?>, I believe this is a bug in the realm, but I guarantee that in the code we are saving it as IList<float?>.
I’m attaching a drive with the old bank (the bank that tries to get “MeasuredValues”) in case it helps with anything. Link drive :
https://drive.google.com/file/d/1rdPrO4Ahk91n5N_7t4nedUfR9h63CQuO/view
The error occurs exactly on this line:
All Code:
if (oldSchemaVersion < 2)
{
var oldOrders = migration.OldRealm.DynamicApi.All(“OrderServiceEntity”);
var newOrders = migration.NewRealm.All();for (int i = 0; i < newOrders.Count(); i++) { var oldOrder = oldOrders.ElementAt(i); var newOrder = newOrders.ElementAt(i); var oldCalibration = oldOrder.DynamicApi.Get<IEmbeddedObject>("Calibration"); var newCalibration = newOrder.Calibration; if (oldCalibration != null) { for (int j = 0; j < oldCalibration.DynamicApi.GetList<IEmbeddedObject>("TablePages").Count; j++) { IEmbeddedObject oldPage = oldCalibration.DynamicApi.GetList<IEmbeddedObject>("TablePages")[j]; var newPage = newCalibration.TablePages[j]; for (int k = 0; k < oldPage.DynamicApi.GetList<IEmbeddedObject>("Rows").Count; k++) { UnityEngine.Debug.LogError(k); var oldRow = oldPage.DynamicApi.GetList<IEmbeddedObject>("Rows")[k]; var newRow = newPage.Rows[k]; // Convertendo o campo Nominal var oldNominal = oldRow.DynamicApi.Get<float?>("Nominal"); newRow.Nominal = oldNominal.HasValue ? oldNominal.Value.ToString() : null; // The error is here on this line: IList<float?> oldMeasuredValues = oldRow.DynamicApi.GetList<float?>("MeasuredValues"); var newMeasuredValues = new List<string?>(); foreach (var value in oldMeasuredValues) { newMeasuredValues.Add(value.HasValue ? value.Value.ToString() : null); } newRow.MeasuredValues.Clear(); foreach (var newMeasured in newMeasuredValues) { newRow.MeasuredValues.Add(newMeasured); } } } } }
}