public string GetData(string name) { if (Record.ContainsKey(name)) { return(Record[name]); } else { return(string.Empty); } }
internal string this[string key] { get { if (Record != null && Record.ContainsKey(key)) { return(Record[key]); } return(null); } }
public override bool TryGetMember(GetMemberBinder binder, out object result) { result = null; if (Record.ContainsKey(binder.Name)) { result = Record[binder.Name]; return(true); } else { return(base.TryGetMember(binder, out result)); } }
public ShipParameterElement this[int i] { get { return(Record.ContainsKey(i) ? Record[i] : null); } set { if (!Record.ContainsKey(i)) { Record.Add(i, value); } else { Record[i] = value; } } }
} // end method protected IRecord GetValues(object obj, IEnumerable<string> tableNames) { var type = obj.GetType(); var mirror = mirrorCache[type]; var values = new Record(StringComparer.OrdinalIgnoreCase); foreach (var tableName in tableNames) { var columns = Executor.GetColumns(tableName); foreach (var column in columns) { if (values.ContainsKey(column)) continue; var propertyName = GetMappedProperty(type, column); var prop = mirror.GetProperty(propertyName, CaseInsensitiveBinding); if (prop != null) values[column] = prop.GetValue(obj, null); } // end for } // end foreach return values; } // end method
public static Entity ToEntity(this Record record, EntityMetadata metadata) { var entity = new Entity(metadata.LogicalName); foreach (var attribute in metadata.Attributes) { if (record.ContainsKey(attribute.ExternalName)) { var value = (object)record[attribute.ExternalName]; entity.Attributes[attribute.LogicalName] = attribute.ToXrm(value); if (attribute.LogicalName == metadata.PrimaryIdAttribute) { entity.Id = (Guid)attribute.ToXrm(value); } } } return(entity); }
public bool Merge(string line) { try { var elem = new ShipParameterElement(line); if (!Record.ContainsKey(elem.ShipID)) { Record.Add(elem.ShipID, elem); return(true); } else { return(Record[elem.ShipID].Merge(elem)); } } catch (Exception) { return(false); } }
public IEnumerable<IDictionary<string, object>> ExecuteRecords(bool schemaOnly, Type connectionType, string connectionString, bool transactional, IsolationLevel isolationLevel, CommandType commandType, string commandText, IEnumerable<DbParameter> commandParameters, Action<int> resultsetCallback = null) { DbTransaction dbTransaction; const bool OPEN = true; IList<IRecord> records; // force no preparation const bool COMMAND_PREPARE = false; // force provider default timeout object COMMAND_TIMEOUT = null; /*int?*/ CommandBehavior commandBehavior; int resultsetIndex = 0; ReadOnlyCollection<DbColumn> dbColumns; DbColumn dbColumn; PropertyInfo[] propertyInfos; PropertyInfo propertyInfo; if ((object)connectionType == null) throw new ArgumentNullException(nameof(connectionType)); if ((object)connectionString == null) throw new ArgumentNullException(nameof(connectionString)); using (DbConnection dbConnection = (DbConnection)Activator.CreateInstance(connectionType)) { if (OPEN) { dbConnection.ConnectionString = connectionString; dbConnection.Open(); if (transactional) dbTransaction = dbConnection.BeginTransaction(isolationLevel); else dbTransaction = null; } using (DbCommand dbCommand = dbConnection.CreateCommand()) { dbCommand.Transaction = dbTransaction; dbCommand.CommandType = commandType; dbCommand.CommandText = commandText; if ((object)COMMAND_TIMEOUT != null) dbCommand.CommandTimeout = (int)COMMAND_TIMEOUT; // add parameters if ((object)commandParameters != null) { foreach (DbParameter commandParameter in commandParameters) { if ((object)commandParameter.Value == null) commandParameter.Value = DBNull.Value; dbCommand.Parameters.Add(commandParameter); } } if (COMMAND_PREPARE) dbCommand.Prepare(); records = new List<IRecord>(); commandBehavior = schemaOnly ? CommandBehavior.SchemaOnly : CommandBehavior.Default; // wrap reader with proxy using (DbDataReader dbDataReader = new WrappedDbDataReader.__(dbCommand.ExecuteReader(commandBehavior))) { Record record; string key; object value; if (!schemaOnly) { do { if ((object)resultsetCallback != null) resultsetCallback(resultsetIndex++); while (dbDataReader.Read()) { record = new Record(); for (int columnIndex = 0; columnIndex < dbDataReader.FieldCount; columnIndex++) { key = dbDataReader.GetName(columnIndex); value = dbDataReader.GetValue(columnIndex); value = this.DataTypeFascade.ChangeType<object>(value); if (record.ContainsKey(key) || (key ?? string.Empty).Length == 0) key = string.Format("Column_{0:0000}", columnIndex); record.Add(key, value); } records.Add(record); } } while (dbDataReader.NextResult()); } else { if (!dbDataReader.CanGetColumnSchema()) throw new NotSupportedException(string.Format("The connection command type '{0}' does not support schema access.", dbDataReader.GetType().FullName)); dbColumns = dbDataReader.GetColumnSchema(); { if ((object)dbColumns != null) { for (int index = 0; index < dbColumns.Count; index++) { dbColumn = dbColumns[index]; propertyInfos = dbColumn.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); record = new Record(); record.Context = dbColumn; if ((object)propertyInfos != null) { for (int i = 0; i < propertyInfos.Length; i++) { propertyInfo = propertyInfos[i]; if (propertyInfo.GetIndexParameters().Any()) continue; key = propertyInfo.Name; value = propertyInfo.GetValue(dbColumn); value = value.ChangeType<object>(); record.Add(key, value); } } } } } } } return records; } } }
/// <summary> /// Execute a command against a data source, mapping the data reader to an enumerable of record dictionaries. /// This method perfoms LAZY LOADING/DEFERRED EXECUTION. /// Note that THE DATA READER WILL NOT BE DISPOSED UPON ENUMERATION OR FOREACH BRANCH OUT. /// </summary> /// <param name="dbDataReader"> The target data reader. </param> /// <param name="recordsAffectedCallback"> Executed when the output count of records affected is available to return (post enumeration). </param> /// <returns> An enumerable of record dictionary instances, containing key/value pairs of data. </returns> public IEnumerable<IRecord> GetRecordsFromReader(DbDataReader dbDataReader, Action<int> recordsAffectedCallback) { IRecord record; int recordsAffected; int recordIndex = 0; string key; object value; OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetRecordsFromReader(...): enter", typeof(AdoNetStreamingFascade).Name)); if ((object)dbDataReader == null) throw new ArgumentNullException(nameof(dbDataReader)); OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetRecordsFromReader(...): before yield", typeof(AdoNetStreamingFascade).Name)); while (dbDataReader.Read()) { record = new Record(); for (int columnIndex = 0; columnIndex < dbDataReader.FieldCount; columnIndex++) { key = dbDataReader.GetName(columnIndex); value = dbDataReader.GetValue(columnIndex).ChangeType<object>(); if (record.ContainsKey(key) || (key ?? string.Empty).Length == 0) key = string.Format("Column_{0:0000}", columnIndex); record.Add(key, value); } OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetRecordsFromReader(...): on yield", typeof(AdoNetStreamingFascade).Name)); yield return record; // LAZY PROCESSING INTENT HERE / DO NOT FORCE EAGER LOAD } OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetRecordsFromReader(...): after yield", typeof(AdoNetStreamingFascade).Name)); recordsAffected = dbDataReader.RecordsAffected; if ((object)recordsAffectedCallback != null) recordsAffectedCallback(recordsAffected); OnlyWhen._PROFILE_ThenPrint(string.Format("{0}::GetRecordsFromReader(...): leave", typeof(AdoNetStreamingFascade).Name)); }
public void WithoutFieldTest() { Record record = new Record { {"Field1", "Value1"}, {"Field2", "Value2"}, {"Field3", "Value3"} }; record = record.WithoutField("Field2"); Assert.IsFalse(record.ContainsKey("Field2")); }