Example #1
0
        internal MappingSchema(MappingSchemaInfo mappingSchemaInfo)
        {
            Schemas = new[] { mappingSchemaInfo };

            ValueToSqlConverter = new ValueToSqlConverter();
        }
Example #2
0
        public MappingSchema(string configuration, params MappingSchema[] schemas)
        {
            var schemaInfo = new MappingSchemaInfo(configuration);

            if (schemas == null || schemas.Length == 0)
            {
                Schemas = new[] { schemaInfo, Default.Schemas[0] };

                ValueToSqlConverter = new ValueToSqlConverter(Default.ValueToSqlConverter);
            }
            else if (schemas.Length == 1)
            {
                Schemas    = new MappingSchemaInfo[1 + schemas[0].Schemas.Length];
                Schemas[0] = schemaInfo;
                Array.Copy(schemas[0].Schemas, 0, Schemas, 1, schemas[0].Schemas.Length);

                var baseConverters = new ValueToSqlConverter[1 + schemas[0].ValueToSqlConverter.BaseConverters.Length];
                baseConverters[0] = schemas[0].ValueToSqlConverter;
                Array.Copy(schemas[0].ValueToSqlConverter.BaseConverters, 0, baseConverters, 1, schemas[0].ValueToSqlConverter.BaseConverters.Length);

                ValueToSqlConverter = new ValueToSqlConverter(baseConverters);
            }
            else
            {
                var schemaList = new List <MappingSchemaInfo>(10)
                {
                    schemaInfo
                };
                var baseConverters = new List <ValueToSqlConverter>(10);

                foreach (var schema in schemas)
                {
                    foreach (var sc in schema.Schemas)
                    {
                        if (schemaList.Contains(sc))
                        {
                            schemaList.Remove(sc);
                        }
                        schemaList.Add(sc);
                    }

                    if (baseConverters.Contains(schema.ValueToSqlConverter))
                    {
                        baseConverters.Remove(schema.ValueToSqlConverter);
                    }
                    baseConverters.Add(schema.ValueToSqlConverter);

                    foreach (var bc in schema.ValueToSqlConverter.BaseConverters)
                    {
                        if (baseConverters.Contains(bc))
                        {
                            baseConverters.Remove(bc);
                        }
                        baseConverters.Add(bc);
                    }
                }

                Schemas             = schemaList.ToArray();
                ValueToSqlConverter = new ValueToSqlConverter(baseConverters.ToArray());
            }
        }