/// <summary>
        /// Common initialization
        /// </summary>
        /// <param name="member">MemberInfo/param>
        /// <param name="dataType">Type of property/field</param>
        private void CommonInit(System.Reflection.MemberInfo member, Type dataType)
        {
            Type = dataType;

            foreach (Attribute attribute in member.GetCustomAttributes(true))
            {
                if (attribute is PartitionKeyAttribute)
                {
                    IsPartitionKey = true;
                }
                else if (attribute is RowKeyAttribute)
                {
                    IsRowKey = true;
                }
                else if (attribute is ETagAttribute)
                {
                    IsETag = true;
                }
                else if (attribute is TimestampAttribute)
                {
                    IsTimestamp = true;
                }
                else if (attribute is TableColumnAttribute tc)
                {
                    // Now the problem is legacy code that may define columns we now have attributes for
                    // as TableColumn() with matching names. So filter those out.

                    switch (tc.ColumnName)
                    {
                    case "ETag":
                        IsETag = true;
                        continue;

                    case "Timestamp":
                        IsTimestamp = true;
                        continue;

                    case "PartitionKey":
                        IsPartitionKey = true;
                        continue;

                    case "RowKey":
                        IsRowKey = true;
                        continue;
                    }

                    // Traditional column
                    TableEntityColumn = tc;
                }
            }

            Type?underlyingType = Nullable.GetUnderlyingType(Type);

            TypeCode  = Type.GetTypeCode(underlyingType ?? Type);
            IsEdmType = EdmTypeConverter.IsEdmCompatibleType(underlyingType ?? Type);

            IsNullableType = (dataType == typeof(string)) || (underlyingType == typeof(string)) || (underlyingType != null);
        }
        public CanonicalFunctionMapper(ITypeConverter converter)
        {
            this.converter = new EdmTypeConverter(converter);
            this.mappings  = new Dictionary <string, Func <EdmFunction, Expression[], Expression> >();

            this.AddStringMappings();
            this.AddDateTimeMappings();
            this.AddMathMappings();
            this.AddBitwiseMappings();
            this.AddMiscMappings();
        }
Example #3
0
        public TransformVisitor(ITypeConverter converter)
        {
            this.converter        = converter;
            this.edmTypeConverter = new EdmTypeConverter(converter);

            this.queryMethodExpressionBuilder = new LinqMethodExpressionBuilder();
            this.currentVariables             = new VariableCollection();
            this.parameters = new Dictionary <string, Tuple <TypeUsage, int> >();

            this.functionMapper = new CanonicalFunctionMapper(converter);
            this.methodProvider = new Effort.Internal.DbManagement.DbMethodProvider();
        }
Example #4
0
        public CanonicalContainer(ItemCollection source, EdmTypeConverter converter)
        {
            this.converter  = converter;
            this.containers = source.GetItems <EntityContainer>().ToList();

            this.entities = new Lazy <ReadOnlyCollection <EntityInfo> >(() =>
                                                                        this.GetEntities()
                                                                        .ToList()
                                                                        .AsReadOnly());

            this.associations = new Lazy <ReadOnlyCollection <AssociationInfo> >(() =>
                                                                                 this.GetAssociations()
                                                                                 .ToList()
                                                                                 .AsReadOnly());
        }
Example #5
0
        private IEnumerable <EntityPropertyInfo> GetProperties(
            IEnumerable <EdmProperty> props,
            EdmTypeConverter converter)
        {
            var groups = props.GroupBy(x => x.GetColumnName());

            foreach (var group in groups)
            {
                var prop = group.First();

                var name    = prop.GetColumnName();
                var facets  = converter.GetTypeFacets(prop.TypeUsage);
                var clrType = converter.Convert(prop.TypeUsage);
                var indexes = GetIndexes(prop).ToList();

                // TODO: verify conflict

                yield return(new EntityPropertyInfo(name, clrType, facets, indexes));
            }
        }
Example #6
0
        public static DbSchema CreateDbSchema(StoreItemCollection edmStoreSchema)
        {
            EdmTypeConverter   converter = new EdmTypeConverter(new DefaultTypeConverter());
            CanonicalContainer container = new CanonicalContainer(edmStoreSchema, converter);

            IBareSchema bareSchema = new DynamicBareSchema(container);

            TableConfigurationGroup tableConfig = new TableConfigurationGroup();

            tableConfig.Register(new BareSchemaConfiguration(bareSchema));
            tableConfig.Register <PrimaryKeyConfiguration>();
            tableConfig.Register <IdentityConfiguration>();
            tableConfig.Register <GeneratedGuidConfiguration>();
            tableConfig.Register <NotNullConfiguration>();
            tableConfig.Register <VarcharLimitConfiguration>();
            tableConfig.Register <CharLimitConfiguration>();
            tableConfig.Register <IndexConfiguration>();

            DbSchemaBuilder schemaBuilder = new DbSchemaBuilder();

            foreach (EntityInfo entityInfo in container.Entities)
            {
                DbTableInfoBuilder tableBuilder = new DbTableInfoBuilder();

                // Run all configurations
                tableConfig.Configure(entityInfo, tableBuilder);

                schemaBuilder.Register(tableBuilder);
            }

            RelationConfigurationGroup associationConfig = new RelationConfigurationGroup();

            associationConfig.Register <RelationConfiguration>();

            foreach (AssociationInfo associationInfo in container.Associations)
            {
                associationConfig.Configure(associationInfo, schemaBuilder);
            }

            return(schemaBuilder.Create());
        }