コード例 #1
0
        /// <summary>
        /// Get EdgeObject fields which are configured in MD_EdgeField table according to object type
        /// get fields values by reflection and compose values and columns string for INSERT
        /// </summary>
        /// <param name="edgeObject"></param>
        /// <param name="columns"></param>
        /// <param name="values"></param>
        /// <param name="paramList"></param>
        private void BuildEdgeObjectFields(EdgeObject edgeObject, ref string columns, ref string values, ICollection <SqlParameter> paramList)
        {
            // get the list of configured fields in MD_EdgeFields according to the object type
            foreach (var field in edgeObject.EdgeType.Fields)
            {
                // add extra field column
                var edgeFieldObj = edgeObject.GetObjectDimensions().Where(x => x.Field == field.Field).Select(x => x.Value).FirstOrDefault() as EdgeObject;
                if (edgeFieldObj != null)
                {
                    AddColumn(ref columns, ref values, paramList, String.Format("{0}_gk", field.ColumnName), edgeFieldObj.GK);
                    AddColumn(ref columns, ref values, paramList, String.Format("{0}_tk", field.ColumnName), edgeFieldObj.TK);
                    AddColumn(ref columns, ref values, paramList, String.Format("{0}_type", field.ColumnName), edgeFieldObj.EdgeType.TypeID);
                }
                else
                {
                    // 1st try to get field from extra fields by name
                    if (edgeObject.Fields != null && edgeObject.Fields.FirstOrDefault(x => x.Key.Name == field.Field.Name).Key != null)
                    {
                        var extraField = edgeObject.Fields.FirstOrDefault(x => x.Key.Name == field.Field.Name);
                        AddColumn(ref columns, ref values, paramList, field.ColumnName, extraField.Value);
                    }
                    else
                    {
                        // try to get field by reflection by configured edge field name
                        var member = edgeObject.GetType().GetMember(field.Field.Name);
                        if (member.Length > 0)
                        {
                            var memberInfo = edgeObject.GetType().GetMember(field.Field.Name)[0];
                            var value      = (memberInfo is FieldInfo ? (memberInfo as FieldInfo).GetValue(edgeObject) : null) ??
                                             (memberInfo is PropertyInfo ? (memberInfo as PropertyInfo).GetValue(edgeObject, null) : null);

                            var type = memberInfo is FieldInfo
                                                                           ? (memberInfo as FieldInfo).FieldType
                                                                           : memberInfo is PropertyInfo ? (memberInfo as PropertyInfo).PropertyType : null;

                            // edge object
                            if (value is EdgeObject)
                            {
                                var edgeObj = value as EdgeObject;
                                AddColumn(ref columns, ref values, paramList, String.Format("{0}_gk", field.ColumnName), edgeObj.GK);
                                AddColumn(ref columns, ref values, paramList, String.Format("{0}_tk", field.ColumnName), edgeObj.TK);
                                AddColumn(ref columns, ref values, paramList, String.Format("{0}_type", field.ColumnName),
                                          edgeObj.EdgeType.TypeID);
                            }
                            else if (value != null)                             // primitive types
                            {
                                // special case for enum value - parse to INT
                                if (type.BaseType == typeof(Enum))
                                {
                                    value = (int)Enum.Parse(type, value.ToString());
                                }
                                AddColumn(ref columns, ref values, paramList, field.ColumnName, value);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Create columns for edge oject (GK and TK)
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="columnName"></param>
        /// <returns></returns>
        private IEnumerable <Column> CreateEdgeObjColumns(EdgeObject obj, string columnName = "")
        {
            var columnList = new List <Column>();

            if (obj.EdgeType == null)
            {
                throw new ConfigurationErrorsException(String.Format("EdgeType is not set for object {0}", obj.GetType()));
            }

            // if column name is not set according to EdgeField set it according to EdgeType
            columnName = String.IsNullOrEmpty(columnName) ? obj.EdgeType.Name : columnName;

            // add 3 columns: GK (to be set later in Identify stage), TK (temp key) and type (from EdgeTypes)
            columnList.Add(new Column {
                Name = String.Format("{0}_gk", columnName), Value = obj.GK, Nullable = true
            });
            columnList.Add(new Column {
                Name = String.Format("{0}_tk", columnName), Value = obj.TK, DbType = SqlDbType.NVarChar, Size = 500, Nullable = true
            });
            columnList.Add(new Column {
                Name = String.Format("{0}_type", columnName), Value = obj.EdgeType.TypeID, DbType = SqlDbType.Int, Nullable = true
            });

            return(columnList);
        }