示例#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);
                }
            }
        }
示例#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);
            }
        }
示例#3
0
文件: Model.cs 项目: gonbike/Destrier
        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);
        }
示例#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));
        }
示例#5
0
 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));
     }
 }
示例#6
0
文件: Model.cs 项目: gonbike/Destrier
 public static Boolean CheckNullStateForColumn(ColumnMember cm, object value)
 {
     if (!cm.ColumnAttribute.CanBeNull)
     {
         return(ReflectionHelper.IsSet(value));
     }
     else
     {
         return(true);
     }
 }
示例#7
0
文件: Model.cs 项目: gonbike/Destrier
        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);
            }
        }