Ejemplo n.º 1
0
        void Init()
        {
            Type t       = this.Type;
            var  members = t.GetMembers(BindingFlags.Public | BindingFlags.Instance);

            Dictionary <MemberInfo, IMRM> mappingMemberMappers = new Dictionary <MemberInfo, IMRM>();
            Dictionary <MemberInfo, Action <object, object> > complexMemberSetters = new Dictionary <MemberInfo, Action <object, object> >();

            foreach (var member in members)
            {
                Type         memberType = null;
                PropertyInfo prop       = null;
                FieldInfo    field      = null;

                if ((prop = member as PropertyInfo) != null)
                {
                    if (prop.GetSetMethod() == null)
                    {
                        continue;//对于没有公共的 setter 直接跳过
                    }
                    memberType = prop.PropertyType;
                }
                else if ((field = member as FieldInfo) != null)
                {
                    memberType = field.FieldType;
                }
                else
                {
                    continue;//只支持公共属性和字段
                }
                MappingTypeInfo mappingTypeInfo;
                if (MappingTypeSystem.IsMappingType(memberType, out mappingTypeInfo))
                {
                    IMRM mrm = MRMHelper.CreateMRM(member, mappingTypeInfo);
                    mappingMemberMappers.Add(member, mrm);
                }
                else
                {
                    if (prop != null)
                    {
                        Action <object, object> valueSetter = DelegateGenerator.CreateValueSetter(prop);
                        complexMemberSetters.Add(member, valueSetter);
                    }
                    else if (field != null)
                    {
                        Action <object, object> valueSetter = DelegateGenerator.CreateValueSetter(field);
                        complexMemberSetters.Add(member, valueSetter);
                    }
                    else
                    {
                        continue;
                    }

                    continue;
                }
            }

            this._mappingMemberMappers = PublicHelper.Clone(mappingMemberMappers);
            this._complexMemberSetters = PublicHelper.Clone(complexMemberSetters);
        }
Ejemplo n.º 2
0
        static MappingTypeSystem()
        {
            Dictionary <Type, MappingTypeInfo> defaultTypeInfos = new Dictionary <Type, MappingTypeInfo>();

            SetItem(defaultTypeInfos, typeof(byte), DbType.Byte);
            SetItem(defaultTypeInfos, typeof(sbyte), DbType.SByte);
            SetItem(defaultTypeInfos, typeof(short), DbType.Int16);
            SetItem(defaultTypeInfos, typeof(ushort), DbType.UInt16);
            SetItem(defaultTypeInfos, typeof(int), DbType.Int32);
            SetItem(defaultTypeInfos, typeof(uint), DbType.UInt32);
            SetItem(defaultTypeInfos, typeof(long), DbType.Int64);
            SetItem(defaultTypeInfos, typeof(ulong), DbType.UInt64);
            SetItem(defaultTypeInfos, typeof(float), DbType.Single);
            SetItem(defaultTypeInfos, typeof(double), DbType.Double);
            SetItem(defaultTypeInfos, typeof(decimal), DbType.Decimal);
            SetItem(defaultTypeInfos, typeof(bool), DbType.Boolean);
            SetItem(defaultTypeInfos, typeof(string), DbType.String);
            SetItem(defaultTypeInfos, typeof(Guid), DbType.Guid);
            SetItem(defaultTypeInfos, typeof(DateTime), DbType.DateTime);
            SetItem(defaultTypeInfos, typeof(DateTimeOffset), DbType.DateTimeOffset);
            SetItem(defaultTypeInfos, typeof(TimeSpan), DbType.Time);
            SetItem(defaultTypeInfos, typeof(byte[]), DbType.Binary);

            _typeInfos        = PublicHelper.Clone(defaultTypeInfos);
            _defaultTypeInfos = PublicHelper.Clone(defaultTypeInfos);
        }
Ejemplo n.º 3
0
        void Init()
        {
            Type t       = this.Type;
            var  members = t.GetMembers(BindingFlags.Public | BindingFlags.Instance);

            Dictionary <MemberInfo, IMRM> mappingMemberMappers = new Dictionary <MemberInfo, IMRM>();
            Dictionary <MemberInfo, Action <object, object> > complexMemberSetters = new Dictionary <MemberInfo, Action <object, object> >();

            foreach (var member in members)
            {
                if (!member.HasPublicSetter())
                {
                    continue;
                }

                //只支持公共属性和字段
                Type memberType = member.GetMemberType();

                MappingTypeInfo mappingTypeInfo;
                if (MappingTypeSystem.IsMappingType(memberType, out mappingTypeInfo))
                {
                    IMRM mrm = MRMHelper.CreateMRM(member, mappingTypeInfo);
                    mappingMemberMappers.Add(member, mrm);
                }
                else
                {
                    Action <object, object> valueSetter = DelegateGenerator.CreateValueSetter(member);
                    complexMemberSetters.Add(member, valueSetter);
                }
            }

            this._mappingMemberMappers = PublicHelper.Clone(mappingMemberMappers);
            this._complexMemberSetters = PublicHelper.Clone(complexMemberSetters);
        }
Ejemplo n.º 4
0
        void Init()
        {
            Type t       = this.Type;
            var  members = t.GetMembers(BindingFlags.Public | BindingFlags.Instance);
            Dictionary <MemberInfo, MRMTuple> mappingMemberMappers           = new Dictionary <MemberInfo, MRMTuple>();
            Dictionary <MemberInfo, Lazy <MemberValueSetter> > memberSetters = new Dictionary <MemberInfo, Lazy <MemberValueSetter> >();

            foreach (var member in members)
            {
                if (!member.HasPublicSetter())
                {
                    continue;
                }

                //只支持公共属性和字段
                Type memberType = member.GetMemberType();

                memberSetters.Add(member, new Lazy <MemberValueSetter>(() =>
                {
                    MemberValueSetter valueSetter = MemberValueSetterContainer.GetMemberValueSetter(member);
                    return(valueSetter);
                }, LazyThreadSafetyMode.ExecutionAndPublication));

                Infrastructure.MappingType mappingType;
                if (MappingTypeSystem.IsMappingType(memberType, out mappingType))
                {
                    MRMTuple mrmTuple = MRMHelper.CreateMRMTuple(member, mappingType);
                    mappingMemberMappers.Add(member, mrmTuple);
                }
            }

            this._mappingMemberMappers = PublicHelper.Clone(mappingMemberMappers);
            this._memberSetters        = PublicHelper.Clone(memberSetters);
        }
Ejemplo n.º 5
0
        public JoinQuery(JoinQuery <T1, T2> jq, LambdaExpression filterPredicate)
        {
            this._dbContext     = jq._dbContext;
            this._rootQuery     = jq._rootQuery;
            this._joinedQueries = PublicHelper.Clone(jq._joinedQueries);

            this._filterPredicates = PublicHelper.CloneAndAppendOne(jq._filterPredicates, filterPredicate);
        }
Ejemplo n.º 6
0
        static Dictionary <string, IMethodHandler> GetMethodHandlers()
        {
            var methodHandlers = new Dictionary <string, IMethodHandler>();

            methodHandlers.Add("Equals", new Equals_Handler());
            methodHandlers.Add("NotEquals", new NotEquals_Handler());

            methodHandlers.Add("Trim", new Trim_Handler());
            methodHandlers.Add("TrimStart", new TrimStart_Handler());
            methodHandlers.Add("TrimEnd", new TrimEnd_Handler());
            methodHandlers.Add("StartsWith", new StartsWith_Handler());
            methodHandlers.Add("EndsWith", new EndsWith_Handler());
            methodHandlers.Add("ToUpper", new ToUpper_Handler());
            methodHandlers.Add("ToLower", new ToLower_Handler());
            methodHandlers.Add("Substring", new Substring_Handler());
            methodHandlers.Add("IsNullOrEmpty", new IsNullOrEmpty_Handler());
            methodHandlers.Add("Replace", new Replace_Handler());

            methodHandlers.Add("ToString", new ToString_Handler());
            methodHandlers.Add("Contains", new Contains_Handler());
            methodHandlers.Add("In", new In_Handler());

            methodHandlers.Add("Count", new Count_Handler());
            methodHandlers.Add("LongCount", new LongCount_Handler());
            methodHandlers.Add("Sum", new Sum_Handler());
            methodHandlers.Add("Max", new Max_Handler());
            methodHandlers.Add("Min", new Min_Handler());
            methodHandlers.Add("Average", new Average_Handler());

            methodHandlers.Add("AddYears", new AddYears_Handler());
            methodHandlers.Add("AddMonths", new AddMonths_Handler());
            methodHandlers.Add("AddDays", new AddDays_Handler());
            methodHandlers.Add("AddHours", new AddHours_Handler());
            methodHandlers.Add("AddMinutes", new AddMinutes_Handler());
            methodHandlers.Add("AddSeconds", new AddSeconds_Handler());
            methodHandlers.Add("AddMilliseconds", new AddMilliseconds_Handler());

            methodHandlers.Add("Parse", new Parse_Handler());

            methodHandlers.Add("NewGuid", new NewGuid_Handler());

            methodHandlers.Add("DiffYears", new DiffYears_Handler());
            methodHandlers.Add("DiffMonths", new DiffMonths_Handler());
            methodHandlers.Add("DiffDays", new DiffDays_Handler());
            methodHandlers.Add("DiffHours", new DiffHours_Handler());
            methodHandlers.Add("DiffMinutes", new DiffMinutes_Handler());
            methodHandlers.Add("DiffSeconds", new DiffSeconds_Handler());
            methodHandlers.Add("DiffMilliseconds", new DiffMilliseconds_Handler());
            methodHandlers.Add("DiffMicroseconds", new DiffMicroseconds_Handler());

            methodHandlers.Add("Abs", new Abs_Handler());

            methodHandlers.Add("NextValueForSequence", new NextValueForSequence_Handler());

            var ret = PublicHelper.Clone(methodHandlers);

            return(ret);
        }
Ejemplo n.º 7
0
        public IGroupingQuery <T> AndBy <K>(Expression <Func <T, K> > keySelector)
        {
            List <LambdaExpression> groupKeySelectors = PublicHelper.CloneAndAppendOne(this._groupKeySelectors, keySelector);

            List <LambdaExpression>      havingPredicates = PublicHelper.Clone(this._havingPredicates);
            List <GroupingQueryOrdering> orderings        = PublicHelper.Clone(this._orderings);

            return(new GroupingQuery <T>(this._fromQuery, groupKeySelectors, havingPredicates, orderings));
        }
Ejemplo n.º 8
0
        static SqlGenerator()
        {
            List <DbExpressionType> safeDbExpressionTypes = new List <DbExpressionType>();

            safeDbExpressionTypes.Add(DbExpressionType.MemberAccess);
            safeDbExpressionTypes.Add(DbExpressionType.ColumnAccess);
            safeDbExpressionTypes.Add(DbExpressionType.Constant);
            safeDbExpressionTypes.Add(DbExpressionType.Parameter);
            safeDbExpressionTypes.Add(DbExpressionType.Convert);
            SafeDbExpressionTypes = safeDbExpressionTypes.AsReadOnly();


            Dictionary <Type, string> castTypeMap = new Dictionary <Type, string>();

            //castTypeMap.Add(typeof(string), "NVARCHAR2"); // instead of using to_char(exp)
            castTypeMap.Add(typeof(byte), "NUMBER(3,0)");
            castTypeMap.Add(typeof(Int16), "NUMBER(4,0)");
            castTypeMap.Add(typeof(int), "NUMBER(9,0)");
            castTypeMap.Add(typeof(long), "NUMBER(18,0)");
            castTypeMap.Add(typeof(float), "BINARY_FLOAT");
            castTypeMap.Add(typeof(double), "BINARY_DOUBLE");
            castTypeMap.Add(typeof(decimal), "NUMBER");
            castTypeMap.Add(typeof(bool), "NUMBER(9,0)");
            //castTypeMap.Add(typeof(DateTime), "DATE"); // instead of using TO_TIMESTAMP(exp)
            //castTypeMap.Add(typeof(Guid), "BLOB");
            CastTypeMap = PublicHelper.Clone(castTypeMap);


            Dictionary <Type, Type> numericTypes = new Dictionary <Type, Type>();

            numericTypes.Add(typeof(byte), typeof(byte));
            numericTypes.Add(typeof(sbyte), typeof(sbyte));
            numericTypes.Add(typeof(short), typeof(short));
            numericTypes.Add(typeof(ushort), typeof(ushort));
            numericTypes.Add(typeof(int), typeof(int));
            numericTypes.Add(typeof(uint), typeof(uint));
            numericTypes.Add(typeof(long), typeof(long));
            numericTypes.Add(typeof(ulong), typeof(ulong));
            numericTypes.Add(typeof(float), typeof(float));
            numericTypes.Add(typeof(double), typeof(double));
            numericTypes.Add(typeof(decimal), typeof(decimal));
            NumericTypes = PublicHelper.Clone(numericTypes);


            int           cacheParameterNameCount = 2 * 12;
            List <string> cacheParameterNames     = new List <string>(cacheParameterNameCount);

            for (int i = 0; i < cacheParameterNameCount; i++)
            {
                string paramName = UtilConstants.ParameterNamePrefix + i.ToString();
                cacheParameterNames.Add(paramName);
            }
            CacheParameterNames = cacheParameterNames;
        }
Ejemplo n.º 9
0
        static SqlGenerator()
        {
            List <DbExpressionType> safeDbExpressionTypes = new List <DbExpressionType>();

            safeDbExpressionTypes.Add(DbExpressionType.MemberAccess);
            safeDbExpressionTypes.Add(DbExpressionType.ColumnAccess);
            safeDbExpressionTypes.Add(DbExpressionType.Constant);
            safeDbExpressionTypes.Add(DbExpressionType.Parameter);
            safeDbExpressionTypes.Add(DbExpressionType.Convert);
            SafeDbExpressionTypes = safeDbExpressionTypes.AsReadOnly();


            Dictionary <Type, string> castTypeMap = new Dictionary <Type, string>();

            castTypeMap.Add(typeof(string), "NVARCHAR(MAX)");
            castTypeMap.Add(typeof(byte), "TINYINT");
            castTypeMap.Add(typeof(Int16), "SMALLINT");
            castTypeMap.Add(typeof(int), "INT");
            castTypeMap.Add(typeof(long), "BIGINT");
            castTypeMap.Add(typeof(float), "REAL");
            castTypeMap.Add(typeof(double), "FLOAT");
            castTypeMap.Add(typeof(decimal), "DECIMAL(19,0)");//I think this will be a bug.
            castTypeMap.Add(typeof(bool), "BIT");
            castTypeMap.Add(typeof(DateTime), "DATETIME");
            castTypeMap.Add(typeof(Guid), "UNIQUEIDENTIFIER");
            CastTypeMap = PublicHelper.Clone(castTypeMap);


            Dictionary <Type, Type> numericTypes = new Dictionary <Type, Type>();

            numericTypes.Add(typeof(byte), typeof(byte));
            numericTypes.Add(typeof(sbyte), typeof(sbyte));
            numericTypes.Add(typeof(short), typeof(short));
            numericTypes.Add(typeof(ushort), typeof(ushort));
            numericTypes.Add(typeof(int), typeof(int));
            numericTypes.Add(typeof(uint), typeof(uint));
            numericTypes.Add(typeof(long), typeof(long));
            numericTypes.Add(typeof(ulong), typeof(ulong));
            numericTypes.Add(typeof(float), typeof(float));
            numericTypes.Add(typeof(double), typeof(double));
            numericTypes.Add(typeof(decimal), typeof(decimal));
            NumericTypes = PublicHelper.Clone(numericTypes);


            int           cacheParameterNameCount = 2 * 12;
            List <string> cacheParameterNames     = new List <string>(cacheParameterNameCount);

            for (int i = 0; i < cacheParameterNameCount; i++)
            {
                string paramName = UtilConstants.ParameterNamePrefix + i.ToString();
                cacheParameterNames.Add(paramName);
            }
            CacheParameterNames = cacheParameterNames;
        }
        static Dictionary <MethodInfo, Action <DbBinaryExpression, SqlGenerator> > InitBinaryWithMethodHandlers()
        {
            var binaryWithMethodHandlers = new Dictionary <MethodInfo, Action <DbBinaryExpression, SqlGenerator> >();

            binaryWithMethodHandlers.Add(UtilConstants.MethodInfo_String_Concat_String_String, StringConcat);
            binaryWithMethodHandlers.Add(UtilConstants.MethodInfo_String_Concat_Object_Object, StringConcat);

            var ret = PublicHelper.Clone(binaryWithMethodHandlers);

            return(ret);
        }
Ejemplo n.º 11
0
        public TypeDescriptor(TypeDefinition definition)
        {
            this.Definition          = definition;
            this.PropertyDescriptors = this.Definition.Properties.Select(a => new PropertyDescriptor(a, this)).ToList().AsReadOnly();

            this.PrimaryKeys   = this.PropertyDescriptors.Where(a => a.Definition.IsPrimaryKey).ToList().AsReadOnly();
            this.AutoIncrement = this.PropertyDescriptors.Where(a => a.Definition.IsAutoIncrement).FirstOrDefault();

            this._propertyDescriptorMap = PublicHelper.Clone(this.PropertyDescriptors.ToDictionary(a => (MemberInfo)a.Definition.Property, a => a));
            this._propertyColumnMap     = PublicHelper.Clone(this.PropertyDescriptors.ToDictionary(a => (MemberInfo)a.Definition.Property, a => new DbColumnAccessExpression(this.Definition.Table, a.Definition.Column)));
        }
Ejemplo n.º 12
0
        static Dictionary <string, Action <DbAggregateExpression, SqlGenerator> > InitAggregateHandlers()
        {
            var aggregateHandlers = new Dictionary <string, Action <DbAggregateExpression, SqlGenerator> >();

            aggregateHandlers.Add("Count", Aggregate_Count);
            aggregateHandlers.Add("LongCount", Aggregate_LongCount);
            aggregateHandlers.Add("Sum", Aggregate_Sum);
            aggregateHandlers.Add("Max", Aggregate_Max);
            aggregateHandlers.Add("Min", Aggregate_Min);
            aggregateHandlers.Add("Average", Aggregate_Average);

            var ret = PublicHelper.Clone(aggregateHandlers);

            return(ret);
        }
Ejemplo n.º 13
0
        static Dictionary<string, IMethodHandler> GetMethodHandlers()
        {
            var methodHandlers = new Dictionary<string, IMethodHandler>();

            var methodHandlerTypes = Assembly.GetExecutingAssembly().GetTypes().Where(a => a.IsClass && !a.IsAbstract && typeof(IMethodHandler).IsAssignableFrom(a) && a.Name.EndsWith("_Handler") && a.GetConstructor(Type.EmptyTypes) != null);

            foreach (Type methodHandlerType in methodHandlerTypes)
            {
                string handleMethodName = methodHandlerType.Name.Substring(0, methodHandlerType.Name.Length - "_Handler".Length);
                methodHandlers.Add(handleMethodName, (IMethodHandler)Activator.CreateInstance(methodHandlerType));
            }

            var ret = PublicHelper.Clone(methodHandlers);
            return ret;
        }
Ejemplo n.º 14
0
        protected IOrderedGroupingQuery <T> CreateOrderedGroupingQuery <K>(Expression <Func <T, K> > keySelector, DbExpressions.DbOrderType orderType, bool append)
        {
            List <LambdaExpression> groupKeySelectors = PublicHelper.Clone(this._groupKeySelectors);
            List <LambdaExpression> havingPredicates  = PublicHelper.Clone(this._havingPredicates);

            List <GroupingQueryOrdering> orderings = new List <GroupingQueryOrdering>();

            if (append)
            {
                orderings.AddRange(this._orderings);
            }
            orderings.Add(new GroupingQueryOrdering(keySelector, orderType));

            return(new OrderedGroupingQuery <T>(this._fromQuery, groupKeySelectors, havingPredicates, orderings));
        }
Ejemplo n.º 15
0
        static SqlGenerator()
        {
            Dictionary <Type, string> castTypeMap = new Dictionary <Type, string>();

            castTypeMap.Add(typeof(string), "CHAR");
            castTypeMap.Add(typeof(byte), "UNSIGNED");
            castTypeMap.Add(typeof(sbyte), "SIGNED");
            castTypeMap.Add(typeof(Int16), "SIGNED");
            castTypeMap.Add(typeof(UInt16), "UNSIGNED");
            castTypeMap.Add(typeof(int), "SIGNED");
            castTypeMap.Add(typeof(uint), "UNSIGNED");
            castTypeMap.Add(typeof(long), "SIGNED");
            castTypeMap.Add(typeof(ulong), "UNSIGNED");
            castTypeMap.Add(typeof(DateTime), "DATETIME");
            castTypeMap.Add(typeof(bool), "SIGNED");
            CastTypeMap = PublicHelper.Clone(castTypeMap);


            Dictionary <Type, Type> numericTypes = new Dictionary <Type, Type>();

            numericTypes.Add(typeof(byte), typeof(byte));
            numericTypes.Add(typeof(sbyte), typeof(sbyte));
            numericTypes.Add(typeof(short), typeof(short));
            numericTypes.Add(typeof(ushort), typeof(ushort));
            numericTypes.Add(typeof(int), typeof(int));
            numericTypes.Add(typeof(uint), typeof(uint));
            numericTypes.Add(typeof(long), typeof(long));
            numericTypes.Add(typeof(ulong), typeof(ulong));
            numericTypes.Add(typeof(float), typeof(float));
            numericTypes.Add(typeof(double), typeof(double));
            numericTypes.Add(typeof(decimal), typeof(decimal));
            NumericTypes = PublicHelper.Clone(numericTypes);


            int           cacheParameterNameCount = 2 * 12;
            List <string> cacheParameterNames     = new List <string>(cacheParameterNameCount);

            for (int i = 0; i < cacheParameterNameCount; i++)
            {
                string paramName = UtilConstants.ParameterNamePrefix + i.ToString();
                cacheParameterNames.Add(paramName);
            }
            CacheParameterNames = cacheParameterNames;
        }
Ejemplo n.º 16
0
        static SqlGenerator()
        {
            Dictionary <Type, string> castTypeMap = new Dictionary <Type, string>();

            castTypeMap.Add(typeof(string), "VARCHAR");
            castTypeMap.Add(typeof(byte), "SMALLINT");
            castTypeMap.Add(typeof(Int16), "SMALLINT");
            castTypeMap.Add(typeof(int), "INTEGER");
            castTypeMap.Add(typeof(long), "BIGINT");
            castTypeMap.Add(typeof(float), "DECIMAL");
            castTypeMap.Add(typeof(double), "DECIMAL");
            castTypeMap.Add(typeof(decimal), "DECIMAL");
            castTypeMap.Add(typeof(bool), "BOOLEAN");
            castTypeMap.Add(typeof(DateTime), "TIMESTAMP");
            //castTypeMap.Add(typeof(Guid), "UNIQUEIDENTIFIER");
            CastTypeMap = PublicHelper.Clone(castTypeMap);


            Dictionary <Type, Type> numericTypes = new Dictionary <Type, Type>();

            numericTypes.Add(typeof(byte), typeof(byte));
            numericTypes.Add(typeof(sbyte), typeof(sbyte));
            numericTypes.Add(typeof(short), typeof(short));
            numericTypes.Add(typeof(ushort), typeof(ushort));
            numericTypes.Add(typeof(int), typeof(int));
            numericTypes.Add(typeof(uint), typeof(uint));
            numericTypes.Add(typeof(long), typeof(long));
            numericTypes.Add(typeof(ulong), typeof(ulong));
            numericTypes.Add(typeof(float), typeof(float));
            numericTypes.Add(typeof(double), typeof(double));
            numericTypes.Add(typeof(decimal), typeof(decimal));
            NumericTypes = PublicHelper.Clone(numericTypes);


            int           cacheParameterNameCount = 2 * 12;
            List <string> cacheParameterNames     = new List <string>(cacheParameterNameCount);

            for (int i = 0; i < cacheParameterNameCount; i++)
            {
                string paramName = UtilConstants.ParameterNamePrefix + i.ToString();
                cacheParameterNames.Add(paramName);
            }
            CacheParameterNames = cacheParameterNames;
        }
Ejemplo n.º 17
0
        public TypeDescriptor(TypeDefinition definition)
        {
            this.Definition = definition;
            this.PrimitivePropertyDescriptors  = this.Definition.PrimitiveProperties.Select(a => new PrimitivePropertyDescriptor(a, this)).ToList().AsReadOnly();
            this.ComplexPropertyDescriptors    = this.Definition.ComplexProperties.Select(a => new ComplexPropertyDescriptor(a, this)).ToList().AsReadOnly();
            this.CollectionPropertyDescriptors = this.Definition.CollectionProperties.Select(a => new CollectionPropertyDescriptor(a, this)).ToList().AsReadOnly();
            this.NavigationPropertyDescriptors = this.ComplexPropertyDescriptors.Cast <PropertyDescriptor>().Concat(this.CollectionPropertyDescriptors.Cast <PropertyDescriptor>()).ToList().AsReadOnly();

            var allPropertyDescriptors = this.PrimitivePropertyDescriptors.AsEnumerable <PropertyDescriptor>().Concat(this.ComplexPropertyDescriptors.AsEnumerable <PropertyDescriptor>()).Concat(this.CollectionPropertyDescriptors.AsEnumerable <PropertyDescriptor>());

            this._propertyDescriptorMap = PublicHelper.Clone(allPropertyDescriptors.ToDictionary(a => (MemberInfo)a.Definition.Property, a => a));

            this.PrimaryKeys   = this.PrimitivePropertyDescriptors.Where(a => a.Definition.IsPrimaryKey).ToList().AsReadOnly();
            this.AutoIncrement = this.PrimitivePropertyDescriptors.Where(a => a.Definition.IsAutoIncrement).FirstOrDefault();
            this.RowVersion    = this.PrimitivePropertyDescriptors.Where(a => a.Definition.IsRowVersion).FirstOrDefault();

            this._primitivePropertyDescriptorMap = PublicHelper.Clone(this.PrimitivePropertyDescriptors.ToDictionary(a => (MemberInfo)a.Definition.Property, a => a));
            this._primitivePropertyColumnMap     = PublicHelper.Clone(this.PrimitivePropertyDescriptors.ToDictionary(a => (MemberInfo)a.Definition.Property, a => new DbColumnAccessExpression(this.Definition.Table, a.Definition.Column)));
        }
Ejemplo n.º 18
0
        static SqlGenerator()
        {
            Dictionary <Type, string> castTypeMap = new Dictionary <Type, string>();

            castTypeMap.Add(typeof(string), "TEXT");
            castTypeMap.Add(typeof(byte), "INTEGER");
            castTypeMap.Add(typeof(Int16), "INTEGER");
            castTypeMap.Add(typeof(int), "INTEGER");
            castTypeMap.Add(typeof(long), "INTEGER");
            castTypeMap.Add(typeof(float), "REAL");
            castTypeMap.Add(typeof(double), "REAL");
            //castTypeMap.Add(typeof(decimal), "DECIMAL(19,0)");//I think this will be a bug.
            castTypeMap.Add(typeof(bool), "INTEGER");
            CastTypeMap = PublicHelper.Clone(castTypeMap);


            Dictionary <Type, Type> numericTypes = new Dictionary <Type, Type>();

            numericTypes.Add(typeof(byte), typeof(byte));
            numericTypes.Add(typeof(sbyte), typeof(sbyte));
            numericTypes.Add(typeof(short), typeof(short));
            numericTypes.Add(typeof(ushort), typeof(ushort));
            numericTypes.Add(typeof(int), typeof(int));
            numericTypes.Add(typeof(uint), typeof(uint));
            numericTypes.Add(typeof(long), typeof(long));
            numericTypes.Add(typeof(ulong), typeof(ulong));
            numericTypes.Add(typeof(float), typeof(float));
            numericTypes.Add(typeof(double), typeof(double));
            numericTypes.Add(typeof(decimal), typeof(decimal));
            NumericTypes = PublicHelper.Clone(numericTypes);


            int           cacheParameterNameCount = 2 * 12;
            List <string> cacheParameterNames     = new List <string>(cacheParameterNameCount);

            for (int i = 0; i < cacheParameterNameCount; i++)
            {
                string paramName = UtilConstants.ParameterNamePrefix + i.ToString();
                cacheParameterNames.Add(paramName);
            }
            CacheParameterNames = cacheParameterNames;
        }
Ejemplo n.º 19
0
        static MappingTypeSystem()
        {
            Dictionary <Type, MappingType> defaultMappingTypes = new Dictionary <Type, MappingType>();

            Add(defaultMappingTypes, new MappingType(typeof(byte))
            {
                DbType = DbType.Byte, DbValueConverter = new Byte_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(sbyte))
            {
                DbType = DbType.SByte, DbValueConverter = new SByte_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(short))
            {
                DbType = DbType.Int16, DbValueConverter = new Int16_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(ushort))
            {
                DbType = DbType.UInt16, DbValueConverter = new UInt16_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(int))
            {
                DbType = DbType.Int32, DbValueConverter = new Int32_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(uint))
            {
                DbType = DbType.UInt32, DbValueConverter = new UInt32_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(long))
            {
                DbType = DbType.Int64, DbValueConverter = new Int64_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(ulong))
            {
                DbType = DbType.UInt64, DbValueConverter = new UInt64_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(float))
            {
                DbType = DbType.Single, DbValueConverter = new Single_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(double))
            {
                DbType = DbType.Double, DbValueConverter = new Double_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(decimal))
            {
                DbType = DbType.Decimal, DbValueConverter = new Decimal_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(bool))
            {
                DbType = DbType.Boolean, DbValueConverter = new Boolean_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(string))
            {
                DbType = DbType.String, DbValueConverter = new String_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(Guid))
            {
                DbType = DbType.Guid, DbValueConverter = new Guid_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(DateTime))
            {
                DbType = DbType.DateTime, DbValueConverter = new DateTime_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(DateTimeOffset))
            {
                DbType = DbType.DateTimeOffset, DbValueConverter = new DateTimeOffset_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(TimeSpan))
            {
                DbType = DbType.Time, DbValueConverter = new TimeSpan_ValueConverter()
            });
            Add(defaultMappingTypes, new MappingType(typeof(byte[]))
            {
                DbType = DbType.Binary, DbValueConverter = new Binary_ValueConverter()
            });

            _mappingTypes = PublicHelper.Clone(defaultMappingTypes);
        }