private List <DMSource> GetByConnection(ConnectionDM connection) { var accessor = DC.Accessor <DMSource>(); var result = GetAll(accessor, (item) => item.ID == connection.ChildID); accessor.Dispose(); NotifyChangeListeners(); return(result); }
public List <ConnectionDM> LoadConnections(Expression <Func <ConnectionDM, bool> > exp, DMSource model, ConnectionDataMap connection) { LoadQuery query = new LoadQuery(connection.SchemaName, connection.TableName); BinaryExpression operation = (BinaryExpression)exp.Body; query.AddWhereFragment(operation, DataObject: connection); //query.AddProperty("ID"); //query.AddProperty(connection.ParentID); //query.AddProperty(connection.ChildID); var targetMap = new TableDataMap(typeof(ConnectionDM)); Dictionary <string, string> currentPropertyMap = new Dictionary <string, string>(); foreach (var entry in targetMap.IDColumns) { var prop = entry.Value; if (Attribute.IsDefined(prop, typeof(LookupPropertyAttribute))) { var idData = entry.Value.GetCustomAttribute(typeof(IDColumnAttribute)) as IDColumnAttribute; var propertyName = idData.ColumnName; var value = (string)connection.GetType().GetProperty(propertyName).GetValue(connection); query.AddProperty(value); currentPropertyMap[value] = propertyName; } else { query.AddProperty(entry.Key.ColumnName); } } List <ConnectionDM> items = new List <ConnectionDM>(); var cmd = db.GetCommand(query.Build()); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { ConnectionDM item = CreateNewItem <ConnectionDM>(); for (var i = 0; i < DATA_MAP.Columns.Count(); i++) { var itemName = reader.GetName(i); if (currentPropertyMap.ContainsKey(itemName)) { itemName = currentPropertyMap[itemName]; } SetItem(itemName, reader.GetString(i), targetMap, item); } items.Add(item); } } return(items); }