private SqlParameter[] CreateProductParameters(FundamentalProduct product) { string sparseXml = ""; //Creates sparse xml tags for all properties in the DetailSet that are not null. foreach (var property in product.DetailSet.GetType().GetProperties()) { //This is a hack, a dirty dirty hack, but it works! //To clarify: Gets the value from an F# Option-type if it is passed. Reflection within a reflection, refleception! if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(FSharpOption <>)) { object optionObj = (property.GetValue(product.DetailSet)); Type objType = optionObj.GetType(); object value = objType.GetProperty("Value").GetValue(optionObj); sparseXml += ColConvert.ToSparseXmlTag(value, property.Name); } else { sparseXml += ColConvert.ToSparseXmlTag(property.GetValue(product.DetailSet), property.Name); } } var parameters = new[] { new SqlParameter("@DataSource", product.DataSource), new SqlParameter("@SourceCode", FSharpOption <string> .get_IsSome(product.SourceCode) ? product.SourceCode.Value : null), new SqlParameter("@RequiredServiceID", FSharpOption <int> .get_IsSome(product.RequiredServiceID) ? product.RequiredServiceID.Value : (int?)null), new SqlParameter("@ProductCode", product.ProductCode), new SqlParameter("@ParentCode", FSharpOption <string> .get_IsSome(product.ParentCode) ? product.ParentCode.Value : null), new SqlParameter("@ProductDescription", product.ProductDescription), new SqlParameter("@ExpectedElementsPerDay", product.ExpectedElementsPerDay), new SqlParameter("@IsPublished", product.IsPublished), new SqlParameter("@RecTime", product.RecTime.DateTime), new SqlParameter("@MapData", FSharpOption <Geography> .get_IsSome(product.MapData) ? product.MapData.Value : null), new SqlParameter("@SQLTimeZoneName", FSharpOption <string> .get_IsSome(product.SQLTimeZoneName) ? product.SQLTimeZoneName.Value : null), //The following parameters are sparse. //Therefore they are represented as a XML string. new SqlParameter("@DetailSet", sparseXml) }; return(parameters); }
public DateTimeOffset AsDateTimeOffset(string col) { return(ColConvert.ToDateTimeOffset(_row[col])); }
public DateTime AsDateTime(string col) { return(ColConvert.ToDateTime(_row[col])); }
public decimal?AsDecimal(string col, decimal?fallback) { return(ColConvert.ToDecimal(_row[col], fallback)); }
public decimal AsDecimal(string col) { return(ColConvert.ToDecimal(_row[col])); }
public double?AsDouble(string col, double?fallback) { return(ColConvert.ToDouble(_row[col], fallback)); }
public double AsDouble(string col) { return(ColConvert.ToDouble(_row[col])); }
public char AsChar(string col) { return(ColConvert.ToChar(_row[col])); }
public long?AsInt64(string col, long?fallback) { return(ColConvert.ToInt64(_row[col], fallback)); }
public long AsInt64(string col) { return(ColConvert.ToInt64(_row[col])); }
public int?AsInt32(string col, int?fallback) { return(ColConvert.ToInt32(_row[col], fallback)); }
public int AsInt32(string col) { return(ColConvert.ToInt32(_row[col])); }
public string AsString(string col) { return(ColConvert.ToString(_row[col])); }
public bool AsBool(string col) { return(ColConvert.ToBool(_row[col])); }
public DateTimeOffset?AsDateTimeOffset(string col, DateTimeOffset?fallback) { return(ColConvert.ToDateTimeOffset(_row[col], fallback)); }
public double?AsSingle(string col, float?fallback) { return(ColConvert.ToSingle(_row[col], fallback)); }
public DateTime?AsDateTime(string col, DateTime?fallback) { return(ColConvert.ToDateTime(_row[col], fallback)); }