/// <summary> /// Converts CLR row data into ErlTuple /// </summary> public ErlTuple RowToErlTuple(Row row, bool keysOnly = false) { var result = new ErlTuple(); result.Add(new ErlAtom(row.Schema.Name)); var keys = new List <IErlObject>(); foreach (var def in row.Schema) { var atr = def[m_Store.TargetName]; if (keysOnly && !atr.Key) { break; } if (keys != null && !atr.Key) { if (keys.Count > 1) { result.Add(new ErlTuple(keys, false)); } else { foreach (var key in keys) { result.Add(key); } } keys = null; } IErlObject erlValue = ErlAtom.Undefined; var clrValue = row.GetFieldValue(def); if (clrValue != null) { Func <object, IErlObject> fconv; if (!CLR_TO_ERL_TYPEMAP.TryGetValue(atr.BackendType, out fconv)) { throw new ErlDataAccessException(StringConsts.ERL_DS_INTERNAL_MAPPING_ERROR + "erltype'{0}' not matched in the dict".Args(atr.BackendType)); } erlValue = fconv(clrValue); } if (keys != null) { keys.Add(erlValue); } else { result.Add(erlValue); } } if (keys != null) { if (keys.Count > 1) { result.Add(new ErlTuple(keys, false)); } else { foreach (var key in keys) { result.Add(key); } } } return(result); }
/// <summary> /// Converts CLR row data into ErlTuple /// </summary> public ErlTuple RowToErlTuple(Row row, bool keysOnly = false) { var result = new ErlTuple(); result.Add(new ErlAtom(row.Schema.Name)); var keys = new List <IErlObject>(); foreach (var def in row.Schema) { var atr = def[m_Store.TargetName]; if (keysOnly && !atr.Key) { break; } if (keys != null && !atr.Key) { if (keys.Count > 1) { result.Add(new ErlTuple(keys, false)); } else { foreach (var key in keys) { result.Add(key); } } keys = null; } IErlObject erlValue = ErlAtom.Undefined; var clrValue = row.GetFieldValue(def); if (clrValue != null) { erlValue = ClrToErlValue(atr.BackendType, clrValue); } if (keys != null) { keys.Add(erlValue); } else { result.Add(erlValue); } } if (keys != null) { if (keys.Count > 1) { result.Add(new ErlTuple(keys, false)); } else { foreach (var key in keys) { result.Add(key); } } } return(result); }