Beispiel #1
0
        /// <summary>
        /// This is called for each new result set (in a multi-resultset query).
        /// </summary>
        private void ParseResultSet()
        {
            ColumnNameMap  = _dr.GetColumnNameMap();
            ColumnIndexMap = _dr.GetColumnIndexMap();

            if (this.CurrentOutputType != null)
            {
                this.HasChildCollectionMembers  = ModelCache.HasChildCollectionMembers(this.CurrentOutputType);
                this.HasReferencedObjectMembers = ModelCache.HasReferencedObjectMembers(this.CurrentOutputType);

                ColumnMemberLookup = ModelCache.GetColumnMemberStandardizedLookup(CurrentOutputType);

                ColumnMemberIndexMap = new List <ColumnMember>();

                foreach (var name in ColumnIndexMap)
                {
                    ColumnMember member = null;
                    if (ColumnMemberLookup.TryGetValue(name, out member))
                    {
                        ColumnMemberIndexMap.Add(member);
                    }
                }

                if (!HasReferencedObjectMembers)
                {
                    _setInstanceValuesFn = ModelCache.GetSetInstanceValuesDelegate(this);
                }
            }
        }
Beispiel #2
0
        private static void AddColumnParameter(ColumnMember cm, object myObject, DbCommand cmd, String connectionName)
        {
            object value = cm.Property.GetValue(myObject, null).DBNullCoalese();

            if (!ModelValidation.CheckNullStateForColumn(cm, value))
            {
                throw new InvalidColumnDataException(cm.ColumnAttribute, value);
            }

            if (!ModelValidation.CheckLengthForColumn(cm, value))
            {
                if (cm.ColumnAttribute.MaxStringLength != default(Int32) && cm.ColumnAttribute.ShouldTrimLongStrings && value != null)
                {
                    value = value.ToString().Substring(0, cm.ColumnAttribute.MaxStringLength - 1);
                }
                else
                {
                    throw new InvalidColumnDataException(cm.ColumnAttribute, value);
                }
            }

            if (cm.ColumnAttribute.SqlDbType == null)
            {
                Execute.Utility.AddParameterToCommand(cm.Name, value, cmd, connectionName);
            }
            else
            {
                Execute.Utility.AddParameterToCommand(cm.Name, value, cmd, connectionName, cm.ColumnAttribute.SqlDbType);
            }
        }
Beispiel #3
0
        public static Member MemberForExpression(MemberExpression memberExp, Dictionary <String, Member> members)
        {
            var visitedNames = new List <String>();

            var com = new ColumnMember(memberExp.Member as PropertyInfo);

            visitedNames.Add(com.Name);

            var visitedMemberExp = memberExp;

            while (visitedMemberExp.Expression.NodeType == ExpressionType.MemberAccess)
            {
                visitedMemberExp = memberExp.Expression as MemberExpression;
                if (visitedMemberExp.Member is PropertyInfo)
                {
                    ReferencedObjectMember rom = new ReferencedObjectMember(visitedMemberExp.Member as PropertyInfo);
                    visitedNames.Add(rom.Name);
                }
                else
                {
                    return(null); //abort!
                }
            }

            visitedNames.Reverse();
            var fullName = String.Join(".", visitedNames);

            Member member;

            members.TryGetValue(fullName, out member);
            return(member);
        }
Beispiel #4
0
        public object Get(ColumnMember member, String columnName = null)
        {
            var columnIndex = GetColumnIndex(columnName ?? member.Name);

            if (columnIndex != null)
            {
                return(Get(member.Type, columnIndex.Value, member.IsNullableType, member.UnderlyingGenericType));
            }

            return(ReflectionHelper.GetDefault(member.Type));
        }
 private void WriteColumn(ColumnMember column)
 {
     if (!String.IsNullOrEmpty(column.TableAlias))
     {
         Buffer.AppendFormat("{0}.{1}", WrapName(column.TableAlias, true), WrapName(column.Name));
     }
     else
     {
         Buffer.AppendFormat("{0}", WrapName(column.Name));
     }
 }
Beispiel #6
0
 public static Boolean CheckNullStateForColumn(ColumnMember cm, object value)
 {
     if (!cm.ColumnAttribute.CanBeNull)
     {
         return(ReflectionHelper.IsSet(value));
     }
     else
     {
         return(true);
     }
 }
Beispiel #7
0
        public static Boolean CheckLengthForColumn(ColumnMember cm, object value)
        {
            if (value == null)
            {
                return(true);
            }

            if (value is String && cm.ColumnAttribute.MaxStringLength != default(Int32))
            {
                return(value.ToString().Length <= cm.ColumnAttribute.MaxStringLength);
            }
            else
            {
                return(true);
            }
        }