internal static Dictionary <string, object> GetParameterDictionary(object EntityObject) { ClassMetadata metadata = new ClassMetadata(EntityObject.GetType()); Dictionary <string, object> param = new Dictionary <string, object>(); var columns = metadata.Columns.Select(c => c.Value) .ToList(); foreach (var column in columns) { if (column.IsIdentifier) { continue; } if (column.IsCustomColumn) { continue; } if (column.IsRelationship && column.RelationshipType == RelationshipType.OneToMany) { continue; } if (column.IsRelationship && column.RelationshipType == RelationshipType.ManyToOne) { var relatedObject = column.FieldInfo.GetValue(EntityObject); if (relatedObject != null) { //Speed Up Stuff var objectMeta = MetadataCache.Get(relatedObject.GetType()); var relationshipIdentifier = objectMeta.GetIdentifierField().GetValue(relatedObject); //ΑΤΤΝ: This fixes #30 var relationshipValue = objectMeta.Columns .Select(c => c.Value) .FirstOrDefault(c => c.ColumnName == column.RelationshipReferenceColumn) ?.FieldInfo .GetValue(relatedObject); param.Add("@" + column.ColumnName, relationshipValue); } else { param.Add("@" + column.ColumnName, DBNull.Value); } } else { param.Add("@" + column.ColumnName, column.FieldInfo.GetValue(EntityObject)); } } return(param); }
internal Dictionary <string, object> GetCustomColumnParameters(object entityObject) { if (entityObject == null) { throw new ArgumentNullException(nameof(entityObject)); } var mainMeta = MetadataCache.Get(entityObject.GetType()); var parameters = new Dictionary <string, object> { { "@customFieldId", this.CustomFieldId }, { "@identifier", mainMeta.GetIdentifierField().GetValue(entityObject) } }; var temp = this.FieldInfo.GetValue(entityObject); switch (temp) { case null: #if DEBUG Debug.Assert(temp == null, $"Custom Column {ColumnName} of {mainMeta.EntityName} is null"); #endif temp = DBNull.Value; break; case string s when string.IsNullOrEmpty(s): #if DEBUG Debug.Assert(1 == 1, $"Custom Column {ColumnName} of {mainMeta.EntityName} is null"); #endif temp = DBNull.Value; break; } parameters.Add("@fieldValue", temp); return(parameters); }