Example #1
0
        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);
        }
Example #2
0
 public DateTimeOffset AsDateTimeOffset(string col)
 {
     return(ColConvert.ToDateTimeOffset(_row[col]));
 }
Example #3
0
 public DateTime AsDateTime(string col)
 {
     return(ColConvert.ToDateTime(_row[col]));
 }
Example #4
0
 public decimal?AsDecimal(string col, decimal?fallback)
 {
     return(ColConvert.ToDecimal(_row[col], fallback));
 }
Example #5
0
 public decimal AsDecimal(string col)
 {
     return(ColConvert.ToDecimal(_row[col]));
 }
Example #6
0
 public double?AsDouble(string col, double?fallback)
 {
     return(ColConvert.ToDouble(_row[col], fallback));
 }
Example #7
0
 public double AsDouble(string col)
 {
     return(ColConvert.ToDouble(_row[col]));
 }
Example #8
0
 public char AsChar(string col)
 {
     return(ColConvert.ToChar(_row[col]));
 }
Example #9
0
 public long?AsInt64(string col, long?fallback)
 {
     return(ColConvert.ToInt64(_row[col], fallback));
 }
Example #10
0
 public long AsInt64(string col)
 {
     return(ColConvert.ToInt64(_row[col]));
 }
Example #11
0
 public int?AsInt32(string col, int?fallback)
 {
     return(ColConvert.ToInt32(_row[col], fallback));
 }
Example #12
0
 public int AsInt32(string col)
 {
     return(ColConvert.ToInt32(_row[col]));
 }
Example #13
0
 public string AsString(string col)
 {
     return(ColConvert.ToString(_row[col]));
 }
Example #14
0
 public bool AsBool(string col)
 {
     return(ColConvert.ToBool(_row[col]));
 }
Example #15
0
 public DateTimeOffset?AsDateTimeOffset(string col, DateTimeOffset?fallback)
 {
     return(ColConvert.ToDateTimeOffset(_row[col], fallback));
 }
Example #16
0
 public double?AsSingle(string col, float?fallback)
 {
     return(ColConvert.ToSingle(_row[col], fallback));
 }
Example #17
0
 public DateTime?AsDateTime(string col, DateTime?fallback)
 {
     return(ColConvert.ToDateTime(_row[col], fallback));
 }