예제 #1
0
        internal DbGeographyAdapter(DbGeography value)
        {
            DebugCheck.NotNull(value);

            _value = value;
        }
예제 #2
0
 /// <summary>
 ///     Simple constructor - just needs the name and type of the column
 /// </summary>
 /// <param name="type"> column type </param>
 /// <param name="name"> column name </param>
 internal ColumnMap(TypeUsage type, string name)
 {
     DebugCheck.NotNull(type);
     _type = type;
     _name = name;
 }
예제 #3
0
        public static EntityType GetKeyNamesType(this EntityType table)
        {
            DebugCheck.NotNull(table);

            return((EntityType)table.Annotations.GetAnnotation(KeyNamesTypeAnnotation));
        }
예제 #4
0
        internal void AddColumnMapping(ColumnMappingBuilder columnMappingBuilder)
        {
            Check.NotNull(columnMappingBuilder, "columnMappingBuilder");
            if (!columnMappingBuilder.PropertyPath.Any() ||
                _columnMappings.Contains(columnMappingBuilder))
            {
                throw new ArgumentException(Strings.InvalidColumnBuilderArgument("columnBuilderMapping"));
            }

            DebugCheck.NotNull(columnMappingBuilder.ColumnProperty);

            _columnMappings.Add(columnMappingBuilder);

            StructuralTypeMapping structuralTypeMapping = this;
            EdmProperty           property;

            // Turn the property path into a mapping fragment nested tree structure.

            var i = 0;

            for (; i < columnMappingBuilder.PropertyPath.Count - 1; i++)
            {
                // The first n-1 properties are complex so we just need to build
                // a corresponding tree of complex type mappings.

                property = columnMappingBuilder.PropertyPath[i];

                var complexPropertyMapping
                    = structuralTypeMapping
                      .PropertyMappings
                      .OfType <ComplexPropertyMapping>()
                      .SingleOrDefault(pm => ReferenceEquals(pm.Property, property));

                ComplexTypeMapping complexTypeMapping = null;

                if (complexPropertyMapping == null)
                {
                    complexTypeMapping = new ComplexTypeMapping(false);
                    complexTypeMapping.AddType(property.ComplexType);

                    complexPropertyMapping = new ComplexPropertyMapping(property);
                    complexPropertyMapping.AddTypeMapping(complexTypeMapping);

                    structuralTypeMapping.AddPropertyMapping(complexPropertyMapping);
                }

                structuralTypeMapping
                    = complexTypeMapping
                      ?? complexPropertyMapping.TypeMappings.Single();
            }

            // The last property has to be a scalar mapping to the target column.
            // Extract it and create the scalar mapping leaf node, ensuring that we
            // set the target column.

            property = columnMappingBuilder.PropertyPath[i];

            var scalarPropertyMapping
                = structuralTypeMapping
                  .PropertyMappings
                  .OfType <ScalarPropertyMapping>()
                  .SingleOrDefault(pm => ReferenceEquals(pm.Property, property));

            if (scalarPropertyMapping == null)
            {
                scalarPropertyMapping
                    = new ScalarPropertyMapping(property, columnMappingBuilder.ColumnProperty);

                structuralTypeMapping.AddPropertyMapping(scalarPropertyMapping);

                columnMappingBuilder.SetTarget(scalarPropertyMapping);
            }
            else
            {
                scalarPropertyMapping.Column = columnMappingBuilder.ColumnProperty;
            }
        }
예제 #5
0
 private ToDecisionDiagramConverter(ConversionContext <T_Identifier> context)
 {
     DebugCheck.NotNull(context);
     _context = context;
 }
예제 #6
0
            public ParameterInliner(DbParameterCollection parameters)
            {
                DebugCheck.NotNull(parameters);

                _parameters = parameters;
            }
예제 #7
0
        private static ICustomTypeDescriptor GetTypeDescriptor(Type type)
        {
            DebugCheck.NotNull(type);

            return(new AssociatedMetadataTypeTypeDescriptionProvider(type).GetTypeDescriptor(type));
        }
예제 #8
0
 // <summary>
 // Set the proxy object's private entity wrapper field value to the specified entity wrapper object.
 // The proxy object (representing the wrapped entity) is retrieved from the wrapper itself.
 // </summary>
 // <param name="wrapper"> Wrapper object to be referenced by the proxy. </param>
 // <returns> The supplied entity wrapper. This is done so that this method can be more easily composed within lambda expressions (such as in the materializer). </returns>
 internal IEntityWrapper SetEntityWrapper(IEntityWrapper wrapper)
 {
     DebugCheck.NotNull(wrapper);
     DebugCheck.NotNull(wrapper.Entity);
     return(Proxy_SetEntityWrapper(wrapper.Entity, wrapper) as IEntityWrapper);
 }
예제 #9
0
        internal EntityProxyTypeInfo(
            Type proxyType,
            ClrEntityType ospaceEntityType,
            DynamicMethod initializeCollections,
            List <PropertyInfo> baseGetters,
            List <PropertyInfo> baseSetters,
            MetadataWorkspace workspace)
        {
            DebugCheck.NotNull(proxyType);
            DebugCheck.NotNull(workspace);

            _proxyType  = proxyType;
            _entityType = ospaceEntityType;

            _initializeCollections = initializeCollections;

            foreach (var relationshipType in GetAllRelationshipsForType(workspace, proxyType))
            {
                _navigationPropertyAssociationTypes.Add(relationshipType.FullName, relationshipType);

                if (relationshipType.Name != relationshipType.FullName)
                {
                    // Sometimes there isn't enough metadata to have a container name
                    // Default codegen doesn't qualify names
                    _navigationPropertyAssociationTypes.Add(relationshipType.Name, relationshipType);
                }
            }

            var entityWrapperField = proxyType.GetField(
                EntityWrapperFieldName, BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

            var Object_Parameter = Expression.Parameter(typeof(object), "proxy");
            var Value_Parameter  = Expression.Parameter(typeof(object), "value");

            Debug.Assert(entityWrapperField != null, "entityWrapperField does not exist");

            // Create the Wrapper Getter
            var lambda = Expression.Lambda <Func <object, object> >(
                Expression.Field(
                    Expression.Convert(Object_Parameter, entityWrapperField.DeclaringType), entityWrapperField),
                Object_Parameter);
            var getEntityWrapperDelegate = lambda.Compile();

            Proxy_GetEntityWrapper = (object proxy) =>
            {
                // This code validates that the wrapper points to the proxy that holds the wrapper.
                // This guards against mischief by switching this wrapper out for another one obtained
                // from a different object.
                var wrapper = ((IEntityWrapper)getEntityWrapperDelegate(proxy));
                if (wrapper != null &&
                    !ReferenceEquals(wrapper.Entity, proxy))
                {
                    throw new InvalidOperationException(Strings.EntityProxyTypeInfo_ProxyHasWrongWrapper);
                }
                return(wrapper);
            };

            // Create the Wrapper setter
            Proxy_SetEntityWrapper = Expression.Lambda <Func <object, object, object> >(
                Expression.Assign(
                    Expression.Field(
                        Expression.Convert(Object_Parameter, entityWrapperField.DeclaringType),
                        entityWrapperField),
                    Value_Parameter),
                Object_Parameter, Value_Parameter).Compile();

            var PropertyName_Parameter = Expression.Parameter(typeof(string), "propertyName");
            var baseGetterMethod       = proxyType.GetPublicInstanceMethod("GetBasePropertyValue", typeof(string));

            if (baseGetterMethod != null)
            {
                _baseGetter = Expression.Lambda <Func <object, string, object> >(
                    Expression.Call(Expression.Convert(Object_Parameter, proxyType), baseGetterMethod, PropertyName_Parameter),
                    Object_Parameter, PropertyName_Parameter).Compile();
            }

            var PropertyValue_Parameter = Expression.Parameter(typeof(object), "propertyName");
            var baseSetterMethod        = proxyType.GetPublicInstanceMethod("SetBasePropertyValue", typeof(string), typeof(object));

            if (baseSetterMethod != null)
            {
                _baseSetter = Expression.Lambda <Action <object, string, object> >(
                    Expression.Call(
                        Expression.Convert(Object_Parameter, proxyType), baseSetterMethod, PropertyName_Parameter, PropertyValue_Parameter),
                    Object_Parameter, PropertyName_Parameter, PropertyValue_Parameter).Compile();
            }

            _propertiesWithBaseGetter = new HashSet <string>(baseGetters.Select(p => p.Name));
            _propertiesWithBaseSetter = new HashSet <string>(baseSetters.Select(p => p.Name));

            _createObject = DelegateFactory.CreateConstructor(proxyType);
        }
예제 #10
0
 // <summary>
 // Constructor - loads all resources into the _children collection
 // </summary>
 // <param name="children"> A list of collections to aggregate </param>
 public MetadataArtifactLoaderComposite(List <MetadataArtifactLoader> children)
 {
     DebugCheck.NotNull(children);
     _children = new ReadOnlyCollection <MetadataArtifactLoader>(new List <MetadataArtifactLoader>(children));
 }
예제 #11
0
        internal MetadataOptimization(MetadataWorkspace workspace)
        {
            DebugCheck.NotNull(workspace);

            _workspace = workspace;
        }
예제 #12
0
        //End identical code

        #region Add

        internal override void AddToLocalCache(IEntityWrapper wrappedEntity, bool applyConstraints)
        {
            DebugCheck.NotNull(wrappedEntity);

            WrappedRelatedEntities[(TEntity)wrappedEntity.Entity] = wrappedEntity;
        }
예제 #13
0
        internal override bool CanSetEntityType(IEntityWrapper wrappedEntity)
        {
            DebugCheck.NotNull(wrappedEntity);

            return(wrappedEntity.Entity is TEntity);
        }
예제 #14
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="DbEntityEntry{TEntity}" /> class.
        /// </summary>
        /// <param name="internalEntityEntry"> The internal entry. </param>
        internal DbEntityEntry(InternalEntityEntry internalEntityEntry)
        {
            DebugCheck.NotNull(internalEntityEntry);

            _internalEntityEntry = internalEntityEntry;
        }
예제 #15
0
        private bool QueryExists(string contextKey)
        {
            DebugCheck.NotNull(contextKey);

            if (_initialExistence == DatabaseExistenceState.DoesNotExist)
            {
                return(false);
            }

            DbConnection connection = null;

            try
            {
                connection = CreateConnection();

                if (_initialExistence == DatabaseExistenceState.Unknown)
                {
                    using (var context = CreateContext(connection))
                    {
                        if (!context.Database.Exists())
                        {
                            return(false);
                        }
                    }
                }

                foreach (var schema in _schemas.Reverse())
                {
                    using (var context = CreateContext(connection, schema))
                    {
                        _currentSchema          = schema;
                        _contextKeyColumnExists = true;

                        // Do the context-key specific query first, since if it succeeds we can avoid
                        // doing the more general query.
                        try
                        {
                            using (new TransactionScope(TransactionScopeOption.Suppress))
                            {
                                contextKey = contextKey.RestrictTo(_contextKeyMaxLength);

                                if (context.History.Count(hr => hr.ContextKey == contextKey) > 0)
                                {
                                    return(true);
                                }
                            }
                        }
                        catch (EntityException entityException)
                        {
                            if (_permissionDeniedDetector != null &&
                                _permissionDeniedDetector(entityException.InnerException))
                            {
                                throw;
                            }

                            _contextKeyColumnExists = false;
                        }

                        // If the context-key specific query failed, then try the general query to see
                        // if there is a history table in this schema at all
                        if (!_contextKeyColumnExists)
                        {
                            try
                            {
                                using (new TransactionScope(TransactionScopeOption.Suppress))
                                {
                                    context.History.Count();
                                }
                            }
                            catch (EntityException entityException)
                            {
                                if (_permissionDeniedDetector != null &&
                                    _permissionDeniedDetector(entityException.InnerException))
                                {
                                    throw;
                                }

                                _currentSchema = null;
                            }
                        }
                    }
                }
            }
            finally
            {
                DisposeConnection(connection);
            }

            return(!string.IsNullOrWhiteSpace(_currentSchema));
        }
예제 #16
0
        public static object GetConfiguration(this EdmProperty property)
        {
            DebugCheck.NotNull(property);

            return(property.Annotations.GetConfiguration());
        }
예제 #17
0
        public HistoryRepository(
            InternalContext usersContext,
            string connectionString,
            DbProviderFactory providerFactory,
            string contextKey,
            int?commandTimeout,
            Func <DbConnection, string, HistoryContext> historyContextFactory,
            IEnumerable <string> schemas                    = null,
            DbContext contextForInterception                = null,
            DatabaseExistenceState initialExistence         = DatabaseExistenceState.Unknown,
            Func <Exception, bool> permissionDeniedDetector = null)
            : base(usersContext, connectionString, providerFactory)
        {
            DebugCheck.NotEmpty(contextKey);
            DebugCheck.NotNull(historyContextFactory);

            _initialExistence         = initialExistence;
            _permissionDeniedDetector = permissionDeniedDetector;
            _commandTimeout           = commandTimeout;
            _existingTransaction      = usersContext.TryGetCurrentStoreTransaction();

            _schemas
                = new[] { EdmModelExtensions.DefaultSchema }
            .Concat(schemas ?? Enumerable.Empty <string>())
            .Distinct();

            _contextForInterception = contextForInterception;
            _historyContextFactory  = historyContextFactory;
            DbConnection connection = null;

            try
            {
                connection = CreateConnection();

                using (var context = CreateContext(connection))
                {
                    var historyRowEntity
                        = ((IObjectContextAdapter)context).ObjectContext
                          .MetadataWorkspace
                          .GetItems <EntityType>(DataSpace.CSpace)
                          .Single(et => et.GetClrType() == typeof(HistoryRow));

                    var maxLength
                        = historyRowEntity
                          .Properties
                          .Single(p => p.GetClrPropertyInfo().IsSameAs(MigrationIdProperty))
                          .MaxLength;

                    _migrationIdMaxLength
                        = maxLength.HasValue
                            ? maxLength.Value
                            : HistoryContext.MigrationIdMaxLength;

                    maxLength
                        = historyRowEntity
                          .Properties
                          .Single(p => p.GetClrPropertyInfo().IsSameAs(ContextKeyProperty))
                          .MaxLength;

                    _contextKeyMaxLength
                        = maxLength.HasValue
                            ? maxLength.Value
                            : HistoryContext.ContextKeyMaxLength;
                }
            }
            finally
            {
                DisposeConnection(connection);
            }

            _contextKey = contextKey.RestrictTo(_contextKeyMaxLength);
        }
예제 #18
0
        public static void SetConfiguration(this EdmProperty property, object configuration)
        {
            DebugCheck.NotNull(property);

            property.GetMetadataProperties().SetConfiguration(configuration);
        }
예제 #19
0
 /// <summary>
 ///     Provides a standard helper method for quoting identifiers
 /// </summary>
 /// <param name="identifier"> Identifier to be quoted. Does not validate that this identifier is valid. </param>
 /// <returns> Quoted string </returns>
 internal static string QuoteIdentifier(string identifier)
 {
     DebugCheck.NotNull(identifier);
     return("[" + identifier.Replace("]", "]]") + "]");
 }
예제 #20
0
        public static int?GetOrder(this EdmProperty tableColumn)
        {
            DebugCheck.NotNull(tableColumn);

            return((int?)tableColumn.Annotations.GetAnnotation(OrderAnnotation));
        }
예제 #21
0
        internal void AddConditionProperty(ConditionPropertyMapping conditionPropertyMap)
        {
            DebugCheck.NotNull(conditionPropertyMap);

            AddConditionProperty(conditionPropertyMap, _ => { });
        }
예제 #22
0
        public static void SetOrder(this EdmProperty tableColumn, int order)
        {
            DebugCheck.NotNull(tableColumn);

            tableColumn.GetMetadataProperties().SetAnnotation(OrderAnnotation, order);
        }
예제 #23
0
        public MigrationsConfigurationFinder(TypeFinder typeFinder)
        {
            DebugCheck.NotNull(typeFinder);

            _typeFinder = typeFinder;
        }
예제 #24
0
        public static string GetUnpreferredUniqueName(this EdmProperty tableColumn)
        {
            DebugCheck.NotNull(tableColumn);

            return((string)tableColumn.Annotations.GetAnnotation(UnpreferredUniqueNameAnnotation));
        }
        internal static Funcletizer CreateQueryFuncletizer(ObjectContext rootContext)
        {
            DebugCheck.NotNull(rootContext);

            return(new Funcletizer(Mode.ConventionalQuery, rootContext, null, null));
        }
예제 #26
0
        public static void SetUnpreferredUniqueName(this EdmProperty tableColumn, string name)
        {
            DebugCheck.NotNull(tableColumn);

            tableColumn.GetMetadataProperties().SetAnnotation(UnpreferredUniqueNameAnnotation, name);
        }
예제 #27
0
        public static DatabaseName GetTableName(this EntityType table)
        {
            DebugCheck.NotNull(table);

            return((DatabaseName)table.Annotations.GetAnnotation(TableNameAnnotation));
        }
        /// <summary>Gets the spatial services for the <see cref="T:System.Data.Entity.Core.Common.DbProviderServices" />.</summary>
        /// <returns>The spatial services.</returns>
        /// <param name="key">Information about the database that the spatial services will be used for.</param>
        public DbSpatialServices GetSpatialServices(DbProviderInfo key)
        {
            DebugCheck.NotNull(key);

            return(GetSpatialServices(_resolver.Value, key, () => this));
        }
예제 #29
0
 // <summary>
 // Structured columnmap constructor
 // </summary>
 // <param name="type"> datatype for this column </param>
 // <param name="name"> column name </param>
 // <param name="properties"> list of properties </param>
 internal StructuredColumnMap(TypeUsage type, string name, ColumnMap[] properties)
     : base(type, name)
 {
     DebugCheck.NotNull(properties);
     m_properties = properties;
 }
예제 #30
0
 // effects: Creates an empty map with keys compared using comparer
 internal KeyToListMap(IEqualityComparer <TKey> comparer)
 {
     DebugCheck.NotNull(comparer);
     m_map = new Dictionary <TKey, List <TValue> >(comparer);
 }