public object[] GetToKeys(object fromKey) { var q = new Query(RelationSourceName, ComposeFromCondition(fromKey)); if (PositionFieldName != null) { q.Sort = new[] { PositionFieldName } } ; var tbl = DalcManager.LoadAll(q); return(tbl.Rows.Cast <DataRow>().Select(r => r[ToFieldName]).ToArray()); } }
public void Set(object fromKey, IEnumerable toKeys) { // load var relationTbl = DalcManager.LoadAll(new Query(RelationSourceName, ComposeFromCondition(fromKey))); var data = ExtraKeys == null ? new Dictionary <string, object>() : new Dictionary <string, object>(ExtraKeys); data[FromFieldName] = fromKey; int pos = 1; foreach (var toKey in toKeys) { DataRow relationRow = relationTbl.Rows.Cast <DataRow>().Where(r => DalcRelationEditor.AreEqual(toKey, r[ToFieldName])).FirstOrDefault(); if (relationRow == null) { relationRow = relationTbl.NewRow(); relationRow[FromFieldName] = fromKey; relationRow[ToFieldName] = toKey; if (ExtraKeys != null) { foreach (var extraKeyEntry in ExtraKeys) { relationRow[extraKeyEntry.Key] = extraKeyEntry.Value; } } relationTbl.Rows.Add(relationRow); } if (PositionFieldName != null) { relationRow[PositionFieldName] = pos++; } } // delete missed relations foreach (DataRow r in relationTbl.Rows) { if (!DalcRelationEditor.Contains(r[ToFieldName], toKeys)) { r.Delete(); } } DalcManager.Update(relationTbl); }