private IEnumerable <SqlDataRecord> ToSqlDataRecords(IEnumerable <Station> stations) { // Construct the Data Record with the MetaData: SqlDataRecord sdr = new SqlDataRecord( new SqlMetaData("Identifier", SqlDbType.NVarChar, 5), new SqlMetaData("Name", SqlDbType.NVarChar, 255), new SqlMetaData("StartDate", SqlDbType.DateTime2), new SqlMetaData("EndDate", SqlDbType.DateTime2), new SqlMetaData("StationHeight", SqlDbType.SmallInt), new SqlMetaData("State", SqlDbType.NVarChar, 255), new SqlMetaData("Latitude", SqlDbType.Real), new SqlMetaData("Longitude", SqlDbType.Real) ); // Now yield the Measurements in the Data Record: foreach (var station in stations) { sdr.SetString(0, station.Identifier); sdr.SetString(1, station.Name); sdr.SetDateTime(2, station.StartDate); sdr.SetNullableDateTime(3, station.EndDate); sdr.SetInt16(4, station.StationHeight); sdr.SetString(5, station.State); sdr.SetFloat(6, station.Latitude); sdr.SetFloat(7, station.Longitude); yield return(sdr); } }
private IEnumerable <SqlDataRecord> ToSqlDataRecords(IEnumerable <Observation> observations) { // Construct the Data Record with the MetaData: SqlDataRecord sdr = new SqlDataRecord( new SqlMetaData("Province", SqlDbType.NVarChar, 100), new SqlMetaData("Country", SqlDbType.NVarChar, 100), new SqlMetaData("Timestamp", SqlDbType.DateTime2), new SqlMetaData("Confirmed", SqlDbType.Int), new SqlMetaData("Deaths", SqlDbType.Int), new SqlMetaData("Recovered", SqlDbType.Int), new SqlMetaData("Lat", SqlDbType.Real), new SqlMetaData("Lon", SqlDbType.Real) ); // Now yield the Measurements in the Data Record: foreach (var observation in observations) { sdr.SetString(0, observation.Province); sdr.SetString(1, observation.Country); sdr.SetDateTime(2, observation.Timestamp); sdr.SetInt32(3, observation.Confirmed); sdr.SetInt32(4, observation.Deaths); sdr.SetInt32(5, observation.Recovered); sdr.SetFloat(6, (float)observation.Lat); sdr.SetFloat(7, (float)observation.Lon); yield return(sdr); } }
/// <summary> /// Sets the float. /// </summary> /// <param name="record">The record.</param> /// <param name="fieldName">Name of the field.</param> /// <param name="value">The value.</param> public static void SetFloat(this SqlDataRecord record, string fieldName, float?value) { int ordinal = GetOrdinal(record, fieldName); if (value.HasValue) { record.SetFloat(ordinal, value.Value); } }
public static void SetNullableFloat(this SqlDataRecord sqlDataRecord, int ordinal, float?value) { if (value.HasValue) { sqlDataRecord.SetFloat(ordinal, value.Value); } else { sqlDataRecord.SetDBNull(ordinal); } }
internal override void SetDataRecordValue(SqlDataRecord record, int ordinal) { if (InputValue == null) { record.SetDBNull(ordinal); } else { record.SetFloat(ordinal, InputValue.Value); } }
private static SqlDataRecord CreateFractalRecord(float?value) { var record = new SqlDataRecord(new SqlMetaData("Value", SqlDbType.Real)); if (value.HasValue) { record.SetFloat(0, value.Value); } else { record.SetDBNull(0); } return(record); }
public static IEnumerable <SqlDataRecord> ToSqlDataRecord <T>(this IEnumerable <T> entity) { List <SqlDataRecord> sqlDataRecordList = new List <SqlDataRecord>(); foreach (var e in entity) { var customSqlMetaData = SqlMetaDataExtensions.ToSqlMetaData(e).ToList(); var sqlMetaData = customSqlMetaData.Select(x => x.SqlMetaData).ToArray(); var sqlDataRecord = new SqlDataRecord(sqlMetaData); for (int i = 0; i < sqlMetaData.Length; i++) { var value = customSqlMetaData.SingleOrDefault(x => x.Name == sqlMetaData[i].Name)?.Value; if (value != null) { sqlDataRecord.SetFloat(i, 1.23F); } } sqlDataRecordList.Add(sqlDataRecord); } return(sqlDataRecordList); }